Skip to main content

Posts

Showing posts from October, 2019

Chrome Extension (part 1): Injecting External Scripts into a Web Page

Recently, I was required to develop a chrome extension for some executives. This plugin only targeted a few of our most visited websites. There was a lot of approaches to implement the extension and all our use cases. One particular challenge was trying to inject scripts from our own CDN into specific web pages. the scripts were required to interact with the page and all variables possible. Since there is a script isolation thing for Chrome Extensions, I felt this was a good challenge to take up in my spare time. Here is a sample of my content script. content.js document.onreadystatechange = function () { console.log("document state is:" + document.readyState); if (document.readyState == "complete") { let randAntiCache = Math.random().toString().split('.')[1]; let scriptURL4="http://localhost.test/testscript.js?v="+randAntiCache; let scriptnode4 = document.createElement("script"); scriptnode4.setAttribute("s