Chrome 扩展程序 –来自同一来源的弹出窗口?
我正在编写一个扩展,它具有在新选项卡/窗口中打开 URL 的功能。据我所知,它需要用户的许可才能明确允许“弹出窗口”。
该扩展的内容脚本被注入到每个网站中,因此用户需要在触发此操作的每个域上授予弹出权限。
有没有办法避免这种情况,让用户只允许弹出一次?
I'm writing an extension that has a feature to open a URL in a new tab/window. I understand that it will require the user's permission to explicitly allow a "popup".
The content script of that extension is injected into every website, hence the user is required to give the popup permission on every domain they trigger this action on.
Is there a way to avoid it, so the user has to only allow the popup once?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
遵循 wOxxOm 的出色领导,这里有一个快速示例,说明如何管理此问题。基本思想是将消息从内容脚本(注入到每个网站中)发送到后台脚本,然后从那里调用 chrome.tabs.create 方法。
contentScript.js
在后台脚本中,您必须接收消息并打开所需的选项卡。
就是这样!以下是一些官方文档的链接:
[https://developer.chrome.com/docs/extensions/mv3/messaging/][1]
[https://developer.chrome.com/docs/extensions/reference/tabs/#opening-an-extension-page-in-a-new-tab][2]
我希望我能够回答您的问题;如果您还有其他要求,请随时问我!这是我的第一个回答,所以我只是希望我没有违反任何准则;)
Following the excellent lead of wOxxOm, here's a quick example of how you could manage this. The basic idea is to send a message from the content script (which is injected into every website) to the background script, and from there call the chrome.tabs.create method.
contentScript.js
In the background Script, then, you would have to receive the message and open the desired tab.
That's it! Here are a few links to the official docs:
[https://developer.chrome.com/docs/extensions/mv3/messaging/][1]
[https://developer.chrome.com/docs/extensions/reference/tabs/#opening-an-extension-page-in-a-new-tab][2]
I hope I was able to answer your question; if you have any other requests feel free to ask me! This is my first SO answer, so I just hope I didn't break any guidelines ;)