Is there any way to open a link using Javascript, and then run code on the newly opened webpage?
For example:
document.querySelector('a').click();
// execute code on new page here...
I have used chrome.tabs.executeScript
to open new tabs and insert Javascript into them, but it doesn't appear to work.
Example of what I am trying to accomplish using chrome.tabs.executeScript
:
chrome.tabs.create(
{
url: "https://www.example.com/",
active: true
},
function(tab) {
chrome.tabs.executeScript(tab.id, {
code: `chrome.tabs.create(
{
url: "https://www.google.com/",
active: true
},
function(tab) {
chrome.tabs.executeScript(tab.id, {
code: "console.log('hello world')"
});
}
)`
});
}
);
Is there any solution to this problem?