简体   繁体   English

无法通过Chrome扩展程序与iFrame进行交互

[英]Unable to interact with iFrame through chrome extension

I have a page containing an iFrame that loads different website and would like to be able to interact (click, focus, select, enter value etc..) with contents of the iFrame. 我有一个页面,其中包含加载不同网站的iFrame,并且希望能够与iFrame的内容进行交互(单击,关注,选择,输入值等)。

So far I am able to check if iFrame has loaded, but once trying to do simple things like hide element in it, nothing happens. 到目前为止,我已经能够检查iFrame是否已加载,但是一旦尝试在其中执行诸如hide element的简单操作,就什么也不会发生。

manifest.json manifest.json

{

  "manifest_version": 2,
  "name": "my Extension",
  "version": "0.1",

  "content_scripts" : [
    {
      "matches": [
        "http://*.myPage.com/*",
        "https://*.iframePage.com/*"
      ],
      "js": ["lib/jquery-2.1.4.min.js", "content.js"]
    }
  ]

}

content.js content.js

console.log('Page Loaded');

var myFrame = $('iframe');

myFrame.ready(function() {
  console.log('Frame Loaded');
});

There is also a warning in chrome saying something along the lines: chrome中还警告了一些内容:

Uncaught SecurityError: Blocked a frame with origin "https://www.iframePage.com" from accessing a frame with origin "http://www.myPage.com".  The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "http". Protocols must match.

Not sure if this is related to issue with extension though. 虽然不确定这是否与扩展问题有关。

This is a Cross Origin Error. 这是跨源错误。

Cross-origin issues are about the communication between iframes. 跨域问题与iframe之间的通信有关。 You can always embed any iframe but, if origin differ, iframes cannot interact with each other. 您始终可以嵌入任何iframe,但是,如果原产地不同,则iframe不能彼此交互。

You cannot access the contents of the iframe. 您无法访问iframe的内容。

The basis of Same Origin Policy is that the window can work in contexts of each other only if they are from same protocol://domain:port, Same Origin Policy的基础是,只有当它们来自相同的协议:// domain:port时,窗口才能在彼此的上下文中工作,

Refer this SO Answer-ways to circumvent Cross Domain . 请参阅此SO Answers规避Cross Domain

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

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