I'm new in chrome extensions developing and during developing i get this error in console when i try to open my extension on start page in chrome browser.
Uncaught (in promise) Error: Cannot access a chrome:// URL
Can i avoid this error or any other ways to fix it?
Also I block opening extension window, but this is not solution of problem
code from App.vue file
chrome.tabs.query(queryOptions, (tabs) => {
let url = tabs[0].url;
if (url.indexOf("chrome://") !== -1) {
window.close();
}
background.js
chrome.action.onClicked.addListener(function(tab) {
chrome.scripting.executeScript({
target: {tabId: tab.id},
files: ['js/inject.js']
});
chrome.scripting.insertCSS({
target: {tabId: tab.id},
files: ['css/inject.css']
});
});
I need to keep this window not opened on start page of browser, but also i need to fix throwing of this error.
Solution, that I get from comment works, just wrap it all in simply check tab.url
:
chrome.action.onClicked.addListener(function(tab) {
console.log(tab.url);
if (tab.url.includes('chrome://')){
console.log('can`t run on start page')
} else {
console.log(tab.url);
chrome.scripting.executeScript({
target: {tabId: tab.id},
files: ['js/inject.js']
});
chrome.scripting.insertCSS({
target: {tabId: tab.id},
files: ['css/inject.css']
});
}