I want to access the properties of a window
object from a background script. I have this in manifest.json
:
{
"..": "..",
"permissions": ["http://*.mysite.net/"],
"background": {
"scripts": ["extension.js"]
}
}
and this in extension.js
:
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if (changeInfo.status === 'complete') {
var tabWindowObject = ??
setInterval(tabWindowObject.someFunction, 10);
}
});
I need it here, not in another place (no content scripts and no script injection). How do I get the tabWindowObject
in extension.js
? In other words, I want to access the context of a tab inside a background script Chrome extension.
Since Chrome is already running in the background, there is less that has to take place behind the scenes before your new browser window appears. This makes the browser feel quick, even on slower machines. Running in the background also allows any Chrome extensions you might have installed to continue to operate.
To find out whats wrong with your background. html, under chrome://chrome/extensions/ (i.e., manage extensions), click on the background. html link. This will load the developer tools but without background.
As the architecture overview explains, the background page is an HTML page that runs in the extension process. It exists for the lifetime of your extension, and only one instance of it at a time is active.
You can just put jquery. js into extension folder and include it in the manifest: { "name": "My extension", ... "content_scripts": [ { "matches": ["http://www.google.com/*"], "css": ["mystyles.
You can't. The extension's background page runs in one process, while the tab that was updated runs in a separate process. Different processes can't share objects, so you can't directly access the window
object of a tab from an extension's background page. You have to use a content script to get extension code to run inside the tab's process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With