简体   繁体   English

Chrome扩展程序:是否可以在单击扩展程序图标之前执行popup.js?

[英]Chrome Extension: Is there a way to execute popup.js before clicking on the extension icon?

What I'm trying to do: 我正在尝试做的是:

I'm building a chrome extension that has a popup, an options page, and content scripts. 我正在构建一个chrome扩展程序,它具有一个弹出窗口,一个选项页面和内容脚本。 So far, I'm able to store preferences set on the options page and get them using popup.js. 到目前为止,我能够存储在选项页面上设置的首选项,并使用popup.js来获取它们。 The popup.js makes a couple of public API calls to get some information X. popup.js进行了两个公共API调用,以获取一些信息X。

What I'm stuck on: 我坚持的是:

I need to be able to run/execute popup.js when the DOM loads, before the extension icon is clicked , so that information X can be injected into the DOM via the content scripts. 在单击扩展图标之前,我需要能够在加载DOM时运行/执行popup.js,以便可以通过内容脚本将信息X注入DOM中。

My question: 我的问题:

Is there a way to execute popup.js before clicking on the extension icon? 有没有一种方法可以在单击扩展图标之前执行popup.js? (Right now, the content scripts loads fine displaying information X, after the the extension icon is clicked) (现在,单击扩展图标后,内容脚本会加载精细的显示信息X)

chrome.storage is fully supported for content scripts, so there is no need to communicate the user preferences from the options page to the content scripts via popup.js or background.js. 内容脚本完全支持chrome.storage ,因此无需通过popup.js或background.js将用户首选项从选项页面传达到内容脚本。

With this in mind, I'm able to access user preferences directly to make the API calls in the content scripts, using storage.sync 考虑到这一点,我可以使用storage.sync直接访问用户首选项以在内容脚本中进行API调用

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

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