Inter frame SOP - Chrome Extension

ε祈祈猫儿з 提交于 2019-12-01 17:14:49

问题


In a Chrome Extension, I'm trying to get gmail compose body content.

An error jumps out sporadically, and does not prevents it from working.

This is being run as a content script. I believe permissions are not the issue here, because when there is a permission missing, the error is different and the operation is blocked by Chrome, definitely not the case.

Error comes out in this line:

encodeURIComponent($canvas.find('iframe').contents().find('body').text());

where

var $canvas = $('#canvas_frame').contents();

Any information on this error and a possible turnaround?


回答1:


You can not read cross site content using javascript. XSS Auditor of Google Chorme will never allow this.

Please have a look at http://en.wikipedia.org/wiki/Same_origin_policy

UPDATE 1 -

There is support for cross site communication using window.postMessage() in Chrome 2+. Please have a look at this documentation https://developer.mozilla.org/en-US/docs/DOM/window.postMessage




回答2:


To give a good answer, we need more information:

  • where exactly you are running this code, is it in the web page, the extension's content script or the etension's background script?
  • Also, what does your manifest.json file look like? Which sites have you asked for permission to run on.

I suspect this is a case of a badly-written error message and really it is saying: your extension does not have permission to run on apis.google.com. In that case, simply add permissions for apis.google.com. More details are in the Chrome extensions docs: http://developer.chrome.com/extensions/manifest.html#permissions



来源:https://stackoverflow.com/questions/11852899/inter-frame-sop-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!