Chrome extension content script re-injection after upgrade or install

There’s a way to allow a content script heavy extension to continue functioning after an upgrade, and to make it work immediately upon installation. Install/upgrade The install method is to simply iterate through all tabs in all windows, and inject some scripts programmatically into tabs with matching URLs. ManifestV3 manifest.json: “background”: {“service_worker”: “background.js”}, “permissions”: [“scripting”], … Read more

Chrome extension code vs Content scripts vs Injected scripts

JavaScript code in Chrome extensions can be divided in the following groups: Extension code – Full access to all permitted chrome.* APIs. This includes the background page, and all pages which have direct access to it via chrome.extension.getBackgroundPage(), such as the browser pop-ups. Content scripts (via the manifest file or chrome.tabs.executeScript) – Partial access to … Read more

Debugging Content Scripts for Chrome Extension

Content scripts’ console.log messages are shown in the web page’s console instead of the background page’s inspector. Adding debugger; works if the Developer Tool (for the web page where your content script is injected) is opened. Therefore, in this case, you should first activate the Developer Tool (of the web page) before clicking the browser … Read more

sendMessage from extension background or popup to content script doesn’t work

In your background page you should call chrome.tabs.query({active: true, currentWindow: true}, function(tabs){ chrome.tabs.sendMessage(tabs[0].id, {action: “open_dialog_box”}, function(response) {}); }); instead of using chrome.extension.sendMessage as you currently do. The chrome.tabs variant sends messages to content scripts, whereas the chrome.extension function sends messages to all other extension components.

Access variables and functions defined in page context using a content script

Underlying cause: Content scripts are executed in an “isolated world” environment. Solution: Inject the code into the page using DOM – that code will be able to access functions/variables of the page context (“main world”) or expose functions/variables to the page context (in your case it’s the state() method). Note in case communication with the … Read more

Chrome extension: accessing localStorage in content script

Update 2016: Google Chrome released the storage API: https://developer.chrome.com/docs/extensions/reference/storage/ It is pretty easy to use like the other Chrome APIs and you can use it from any page context within Chrome. // Save it using the Chrome extension storage API. chrome.storage.sync.set({‘foo’: ‘hello’, ‘bar’: ‘hi’}, function() { console.log(‘Settings saved’); }); // Read it using the storage … Read more

Use a content script to access the page context variables and functions

Underlying cause: Content scripts are executed in an “isolated world” environment. Solution: Inject the code into the page using DOM – that code will be able to access functions/variables of the page context (“main world”) or expose functions/variables to the page context (in your case it’s the state() method). Note in case communication with the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)