I'm writing a chrome extension which will open new tab. My question is how can I get the newly opened tab? When I reach that new tab, I want to make some changes in the source code. This; https://developer.chrome.com/extensions/tabs#method-create creates new tab. But I want to make some changes before user click the tab. (Change the selected value and run inside function)
How can I do this with method create?
There is a callback parameter for chrome.tabs.create
, you could call chrome.tabs.executeScript
inside it and inject some code into the created tab.
chrome.tabs.create({url: 'http://www.google.com'}, function(tab) {
chrome.tabs.executeScript(tab.id, {code: 'document.body.style.backgroundColor = 'green;'});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.