本文介绍了frameId设置时,executeScript / insertCSS失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在研究一个背景chrome扩展,并发现我不能将js或css插入到特定的框架中。按照当前的chrome.tabs API文档 https://developer.chrome.com/extensions / tabs#method-executeScript : b $ b 我有一个在调用中使用有效的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 支持 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: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失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-27 10:27