Spurious errors are reported when navigating to chrome:// URLs
tunetheweb opened this issue · 0 comments
Describe the bug
Navigating to chrome://
or chrome-extension://
or chrome-search://
URLs (e.g. the extensions's own options page!) leads to errors, which are particularly confusing for the developers of the extension who don't understand them
To Reproduce
Steps to reproduce the behavior.
- Turn on the extension
- Navigate to the options page
- Check errors in either the Errors screen (if testing an unreleased dev install) or the Service Worker "Inspect Views"
Expected behavior
We should only load the extension on real web pages (i.e. those starting with http
like https://
or http://
).
We do have a check for this in one of the two event listeners:
web-vitals-extension/service_worker.js
Lines 53 to 67 in dd624b9
But not in the other:
web-vitals-extension/service_worker.js
Lines 72 to 74 in dd624b9
This is because this event doesn't have access to the URL.
This works to catch the error:
function getWebVitals(tabId) {
chrome.scripting.executeScript({
target: { tabId: tabId },
files: ['src/browser_action/vitals.js'],
}, (result) => {
// Catch errors such as "This page cannot be scripted due
// to an ExtensionsSettings policy."
let error = chrome.runtime.lastError;
if (error && error.message &&
!error.message.startsWith("Cannot access contents of url \"chrome") &&
!error.message.startsWith("Cannot access a chrome:// URL")
) {
console.error(error.message);
}
});
}
But seems a bit brittle depending on the exact wording, not to mention I'd prefer to prevent the code from executing rather than catch the exception.
You also change allow these URLs in the manifest (for pretty good reason to be honest!).
Have asked our resident extensions Dev Rel (Oliver) for advice.
Version:
- OS w/ version: MacOS Ventura 13.3.1
- Browser w/ version Chrome 112