If you want to set styles depending on conditions, some criteria or based on the content of the page, then use the software add.
In rows
chrome.tabs.insertCSS(null,{file:"css/my_style.css"});
and
chrome.tabs.executeScript({ code: 'document.body.style.backgroundColor="red"' });
You do not specify the tabId parameter.
The script; defaults to the active tab of the current window.
Because of this, the code will be executed for the current active tab, and not in the specific tab you defined.
You can use the query function.
This function will return all tabs that meet the criteria you specified.
For example, tabs with the specified page header, active or inactive, status, url, and so on.
A complete list of parameters is listed here .
Read Programmatic injection
You can make the assumption that you call the executeScript and insertCSS from
"content_scripts": [{ "matches": ["www.site1.ru/javascript/\*", "site2.ru/javascript/\*"], "css": ["css/my_style.css"], "js": ["content_scripts.js"] }]
=> content_scripts.js
In this case, they will not work for sure, because
Here are some examples of content scripts can do:
- Find unlinked URLs in web pages and convert them into hyperlinks
- Increase text
- However, content scripts have some limitations.
They cant:
Use chrome. * APIs, with the exception of:
- extension (getURL, inIncognitoContext, lastError, onRequest, sendRequest)
- i18n
- runtime (connect, getManifest, getURL, id, onConnect, onMessage, sendMessage)
- storage
Use Use
Ie content_scripts cannot use chrome.tabs.api* functionality.
If you need to use this functionality, then you need to put the code in the background script.
In manifest.json
"background": { "scripts": ["script.js"] }
And actions with tabs perform in it.
Read about Execution environment
pluginlabel. In this matter, it does not make sense. - VenZellplugindoes not make sense. You already have a label chrome-extension - VenZell