Unchecked runtime.lastError while running tabs.executeScript?

ε祈祈猫儿з 提交于 2019-11-26 11:56:16
kalman

Both of these errors explain the problem well:

"webkitNotifications is not defined" - this is because webkitNotifications has been removed. I found Chrome webkitNotification not found : api missing which explains what is going on.

"Cannot access a chrome:// URL" - you must be trying to execute the script on a chrome:// URL (like chrome://settings, chrome://extensions) which is illegal. To avoid the error printing like that, you can either - check chrome.runtime.lastError - make sure not to inject onto chrome:// pages.

"Check" runtime.lastError by "reading" it in the callback.


Code

chrome.tabs.executeScript(tabId, {
  //..
}, _=>chrome.runtime.lastError /* "check" error */)

Eg

Show it via..

chrome.tabs.executeScript(tabId, {
  //..
}, _=>{
  let e = chrome.runtime.lastError;
  if(e !== undefined){
    console.log(tabId, _, e);
  }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!