当使用window.open(自Chrome 45以来)打开新选项卡时,Chrome扩展内容脚本作用域是否共享? [英] Is Chrome extension Content Script scope shared when opening a new tab with window.open (since Chrome 45)?

查看:416
本文介绍了当使用window.open(自Chrome 45以来)打开新选项卡时,Chrome扩展内容脚本作用域是否共享?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



问题是,用于单独加载的内容脚本用于每个选项卡现在似乎在打开的选项卡和其开启者选项卡(使用window.open)之间共享一个范围,只要新选项卡与打开者位于相同的域中。



有趣的是,直到今天,当我的Chrome升级到最新的稳定版本(45)时,情况并非如此,但是我还是无法在发行说明中找到任何有关此问题的内容好吧,我错过了)。



我的问题是,这是否确实是新的Chrome的变化?如果是这样,我该如何防止这种情况发生或解决它? 解决方案

根据你的内容脚本在那里做什么可能是解决这个问题的不同方法。



到目前为止,我已经注意到在Chrome 45中 chrome.tabs.sendMessage(tabId,{message :text})发送给 tabId 也被这个标签的开启者标签的内容脚本接收到,解决办法是(意味着你想发送消息到主框架的内容脚本):

  try {chrome.tabs.sendMessage(tabId,message,{frameId:0} )} //在41之前的Chrome上抛出
catch(e){chrome.tabs.sendMessage(tabId,message)}

我认为这是一个错误,显然它是在此修复程序中引入的此错误


I have an extension which used to work fine until the latest update to Chrome (45).

The problem is that the content scripts that used to load separately for each tab, now seem to share scope between an opened tab and its opener tab (when using window.open), as long as the new tab is on the same domain as the opener.

The interesting thing is that this wasn't the case until today, when my Chrome was updated to the latest stable version (45), yet I wasn't able to find anything in the release notes about this (could very well be I missed it).

My question is whether this is indeed a change with the new Chrome? And if it is, how can I prevent this from happening or work around it?

解决方案

Depending on what your content scripts do there could be different ways to tackle the problem.

So far I've noticed that in Chrome 45 chrome.tabs.sendMessage(tabId, {message:"text"}) sent to tabId is received also by this tab's opener tab's content script and the workaround is (implying you want to send the message to the main frame's content script):

try {chrome.tabs.sendMessage(tabId, message, {frameId: 0})} // throws on Chrome prior to 41
catch(e) {chrome.tabs.sendMessage(tabId, message)}

I think this is a bug and evidently it was introduced in this fix of this bug.

这篇关于当使用window.open(自Chrome 45以来)打开新选项卡时,Chrome扩展内容脚本作用域是否共享?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆