Hi folks!
TL;DR: chrome.debugger.attach() will use the last committed URL of a tab. If attaching to a new tab, wait for the tab to commit before attaching the debugger.
What's Changing
Beginning in Chrome 86.0.4224.0, the chrome.debugger.attach() function will use the last committed URL of a tab. Previously, the debugger.attach() function would check the visible URL of a tab to see if it could connect to the tab. Using the last committed URL provides stronger security, as the last committed URL is a better indication of the contents of the tab.
What You Should Check
If you use the debugger.attach() function, verify your extension works in Chrome Canary. If you were using debugger.attach() on a new tab, it is possible that it will now be rejected. You should instead wait for the tab to commit (or complete loading) before attaching.
For instance, the following code may fail.
chrome.tabs.create({url: 'https://example.com'}, (tab) => {
// This may fail, since the tab is not guaranteed to have
// committed at this point.
chrome.debugger.attach({tabId: tab.id}, '1.3');
});
Instead, you can use the tabs.onUpdated() or the webNavigation.onCommitted() events to monitor for the tab load (the latter gives the most accurate timing).
chrome.webNavigation.onCommitted.addListener((details) => {
// Make sure it's the tab you're interested in.
if (!isRightTab(details))
return;
chrome.debugger.attach({tabId: details.tabId}, '1.3');
});
What if I need to attach before commit / by commit time?
If you need to attach to a tab before commit or exactly at commit (in which case attaching in response to the onCommitted event would be too late), you can attach the extension to an existing tab the extension is allowed to connect to, and then update the tab appropriately. In many cases, simply connecting and then refreshing the page would work for this. It's also worth noting that this was inherently racy before, as there was no guarantee that the tab may not have committed at a given point.
Please let us know if you have any questions!
Cheers,
- Devlin, on behalf of the Chrome Extensions team
--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/5faeb9b9-18d8-423a-a2b7-8d6f87774793n%40chromium.org.
We have no control over <a target="_blank" > link, since our extension may be use on different websites, so we are not able to do event.preventDefault. Also we need to support <form target="_blank" > as well.