简体   繁体   English

在页面加载时运行 chrome 扩展

[英]run chrome extension on page load

i have found this extension Behind The Overlay which removes the overlay on the webpage that we visit.Behind The Overlay找到了这个扩展,它删除了我们访问的网页上的覆盖。 for doing so we have to click on the extension icon.为此,我们必须单击扩展图标。

i want to do this programmatically.我想以编程方式执行此操作。 ie on page load the extension should run automatically即在页面加载时扩展应该自动运行

https://github.com/NicolaeNMV/BehindTheOverlay https://github.com/NicolaeNMV/BehindTheOverlay

i want to add delay before this line我想在这条线之前添加延迟

 chrome.tabs.executeScript(null, {file: "overlay_remover.js"});

how to do this?这个怎么做?

chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
  if (changeInfo.status === 'complete' && tab.active) {

    // add some delay here


    chrome.tabs.executeScript(null, {file: "overlay_remover.js"});
  }
})

You can do that by editing your background.js replacing alert() with chrome.tabs.executeScript(null, {file: "/js/overlay_remover.js"});你可以通过编辑你的 background.js 来做到这一点,用chrome.tabs.executeScript(null, {file: "/js/overlay_remover.js"});替换alert() ); and include the overlay remover in your files:并在您的文件中包含覆盖去除器

chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
  if (changeInfo.status === 'complete' && tab.active) {
    setTimeout(() => {
      chrome.tabs.executeScript(null, {file: "overlay_remover.js"});
    }, 3000); // 3000 = delay in milliseconds (3 seconds)
  }
})

Note that you should keep your manifest the same and keep your background.js请注意,您应该保持清单不变并保持 background.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM