frameId设置时,executeScript / insertCSS失败 [英] executeScript / insertCSS fails when frameId set
问题描述
我正在研究一个背景chrome扩展,并发现我不能将js或css插入到特定的框架中。按照当前的chrome.tabs API文档 https://developer.chrome.com/extensions / tabs#method-executeScript : b
$ b
如果allFrames为true,意味着JavaScript或CSS应该注入所有框架的当前页面。默认情况下,它是错误的,只被注入顶部框架。如果设置了true和frameId,那么代码将被插入到所选框架及其所有子框架中。
我有一个在调用中使用有效的frameId,但不管在 details.frameId
中设置了什么,调用将失败并显示以下错误:
chrome.tabs.executeScript(tabId,{
code:'document.body.style.backgroundColor =red',
allFrames:true ,
frameId:frameId
});
错误:参数2的值无效。属性'frameId':意外的属性。
设置 frameId = 0
(总是一个有效的框架 - 顶部框架)仍然失败。我必须删除 executeScript
或 insertCSS
frameId 属性>成功。这个记录的功能没有实际实现吗?
经过进一步的研究,正如Rob W所说,文档是错误的... frameId < Chrome 39支持code>支持
executeScript
和 insertCSS
为 NOT 该文件指出。目前版本的Chrome 49(49.0.2623.110)不支持它。
我已经成功地让他们在当前的Chrome版本(51.0。
更新: Chrome 50.0.2661.75支持 frameId
c $ c> executeScript 和 insertCSS
。
I am working on a background chrome extension and have found that I cannot insert js or css into a specific frame. As per the current chrome.tabs API documentation https://developer.chrome.com/extensions/tabs#method-executeScript:
If allFrames is true, implies that the JavaScript or CSS should be injected into all frames of current page. By default, it's false and is only injected into the top frame. If true and frameId is set, then the code is inserted in the selected frame and all of its child frames.
I DO have a valid frameId to use in the call, but regardless of whatever is set in details.frameId
, the call fails with the following error:
chrome.tabs.executeScript(tabId, {
code: 'document.body.style.backgroundColor="red"',
allFrames: true,
frameId: frameId
});
Error: Invalid value for argument 2. Property 'frameId': Unexpected property.
Setting frameId = 0
(always a valid frame - the top frame) still fails. I have to REMOVE the frameId
property for the executeScript
or insertCSS
to succeed. Is this documented feature not actually implemented?
After further research, as Rob W stated, the documentation is wrong... frameId
support for executeScript
and insertCSS
is NOT supported in Chrome 39 as the documentation states. It is not supported as of the current release of Chrome 49 (49.0.2623.110).
I have successfully got them to work in the current canary release of Chrome (51.0.2699.0).
Update: Chrome 50.0.2661.75 supports frameId
in both executeScript
and insertCSS
.
这篇关于frameId设置时,executeScript / insertCSS失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!