Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome extension: Replace HTML before loading the page

I have a question about how to change web pages with a Chrome extension.

After reading some info I think the question is how to manipulating the DOM. Let's say I open www.stackoverflow with Chrome and want to replace the following line of code:

 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>

and replace it with:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.min.js"></script>

My question is not if it's a smart thing to do, but how to do this?

like image 289
Citizen SP Avatar asked Dec 16 '11 12:12

Citizen SP


1 Answers

Try to modify you manifest's file run_at string.

In the case of "document_start", the files are injected after any files from css, but before any other DOM is constructed or any other script is run.

https://developer.chrome.com/docs/extensions/mv2/content_scripts/

like image 150
Badr Hari Avatar answered Oct 14 '22 02:10

Badr Hari