Reputation: 578
I'm trying to make a chrome extension go to a predefined link on the currently open tab. I can't figure out how to do this. Any ideas?
Upvotes: 0
Views: 131
Reputation: 436
Add the following code in the background.js, Which handles the click event on extension.
chrome.browserAction.onClicked.addListener(() => {
chrome.tabs.query({ active: true }, (tabs) => {
const tab = tabs[0];
chrome.tabs.update(tab.id, {
url: 'https://stackoverflow.com/questions/68945425/update-and-run-pre-defined-link-on-current-tab-chrome-extension',
});
});
});
Code Explanation
chrome.tabs.query
API.chrome.tabs.query
will return an array of tabs.chrome.tabs.update
API.Reference https://developer.chrome.com/docs/extensions/reference/tabs/#method-update
Upvotes: 1