Chrome extension to read HTTP response

I achieved capturing all HTTP requests and responses made by a website, by injecting a script to DOM. I injected injected.js to DOM using following script: /** * code in inject.js * added “web_accessible_resources”: [“injected.js”] to manifest.json */ var s = document.createElement(‘script’); s.src = chrome.extension.getURL(‘injected.js’); s.onload = function() { this.remove(); }; (document.head || document.documentElement).appendChild(s); This … Read more

sending message to chrome extension from a web page

According to the official docs you should use postMessage in the sender and message event listener in the receiver. Here is an example: Your website’s page.html var data = { type: “FROM_PAGE”, text: “Hello from the webpage!” }; window.postMessage(data, “*”); Content script: (injected using chrome.tabs.executeScript(tabid, {code:…) window.addEventListener(“message”, function(event) { // We only accept messages from … Read more

Firefox extension .xpi file structure: description, contents, creation, and installation

.xpi file format (Extension Packaging) The .xpi files that are used as containers for Mozilla (Firefox, Thunderbird, etc.) extensions are merely zip archives that have had the file extension changed to .xpi with the files added to the archive using either “deflate” compression, or uncompressed. If you use any other type of compression, other than … Read more

Injecting iframe into page with restrictive Content Security Policy

The inability to insert an external iframe in Chrome is a bug (crbug.com/408932). If you want to embed an external frame in an external website, then it must be loaded in a frame that is packaged with your extension. manifest.json { “name”: “Embed external site”, “version”: “1”, “manifest_version”: 2, “content_scripts”: [{ “js”: [“contentscript.js”], “matches”: [“*://*/*”], … Read more

Port error while changing chrome extension from manifest v1 to v2

The most likely cause of failure is the activation of the default Content security policy when “manifest_version”: 2 is active. A consequence of the default CSP is that inline JavaScript will not be executed. <script>chrome.extension.onConnect.addListener(…);</script> The previous line is an example of inline code. The solution is to place the script in an external JS … Read more