Browser Extension the "Injected way" a cross-browser extension that include a JS from a distant server

StackOverflow https://stackoverflow.com/questions/16362360

سؤال

I've found this nice article about the "injected Way", but the author never finished it : http://hightechstartups.blogspot.ch/2012/05/different-way-of-developing-browser.html

I would like a bare bone cross browser extension, without any 3rd party extensions or framework (to be as light as possible and not dependant on a 3rd party) that would load Jquery and a JS from a distant server and the ability to load it before or after the page is fully loaded.

I've read a lot of topics about the subject, but since IE10, Chrome 26 and FF20 are out with their new cross-link limitations, i was wondering if somebody had ressources, source code or tutorial about the following requirements :

I need :

  • Cross browser extension supporting (IE 8+ or 9+ worse case, Chrome 26+, FF20+, Safari)

    • Ability to inject a single JS hosted on another server. Inserts a script tag that references a javascript file in the head of the HTML page and then be executed

    • Not be dependant on a third party extension (greasmonkey) or framework (Kango, Crossrider)

    • Ability to load before or after the page is fully loaded

This method allows me to customise the browser extension depending on the user's location and it also avoid having updates as the JS is updated on each page refresh. I'm aware of the downsides, but i would like to achieve this.

I'm aware of cross browser framework like Kango or crossrider, but both don't fit me needs.

The closest example i could find is this How can I run a <script> tag that I just inserted dynamically from a BHO but it only covers IE and as i got very little Csharp experience, i would like to see a full example to understand it properly and learn from example.

I would LOVE to have a few examples, even if it's not cross-browser (IE being the worst part for me). Thanks a lot for your support !

Update1:

About Kango and Crossrider, Kango is 2000$ if you want to use IE and for Crossrider you're required to be distributed and monetized by them.

I've managed to code for IE and Chrome, but i was looking for an "elegant" way and figured it was the best place to ask given the level of knowledge of people on this site.

For the installer i currently use NSIS, but i'll test Wix too.

Finally i guess the only way for me would be to learn C++ and .net to get it to work with IE, but if anyone could provide more source code it would be great to test speed and compatibility and discuss here what's the best solution.

هل كانت مفيدة؟

المحلول

Why do Kango or Crossrider not fit your needs? Both frameworks allow you to manipulate the page's DOM (which is what you want):

If you want to code your own solution, take a look at the relevant documentation:

Internet Explorer does not natively support extensions. It took me about 80 hours to create a stable and reliable IE extension which supports cross-site AJAX, a (preference) storage method and injection of scripts as early as possible in any frames based on its URL. I developed and tested the extension with Visual Express 2010 on Windows XP and Windows 7, for IE 8-10 (the extension might work on IE6/7, but I decided to not support these ancient and rarely used browsers).

First, I wrote an extension in C# based on LiveReloadIEExtension (a sample IE extension, which in turn is based on this Stack Overflow answer - see also this blog post). It was functional, but it required .NET 4, lacked support of frames, and it's relatively slow.

So, I decided to write an IE extension from scratch in C++. A good starting point is available at http://www.wischik.com/lu/programmer/bho.html: Sample code for C++ BHO, which changes the document's background based on key/mouse events. I've also learned a lot by looking at other code samples on CodeProject, topics on the MSDN forums, questions and answers on Stack Overflow, lots of other blogs, and the MSDN documentation:

After creating the IE extension, you want to deploy it of course. I used Wix toolset to create a MSI.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top