Chrome扩展程序添加iframe并访问父窗口内容

时间:2022-08-26 21:32:39

I inject a iframe from content script into a page. The iframe run an angular application. I want to access the parent window's content from this angular script. How can I do it?

我将内容脚本中的iframe注入页面。 iframe运行角度应用程序。我想从这个角度脚本访问父窗口的内容。我该怎么做?

Partial manifest.json

"content_scripts": [
    {
        "css": [
            "css/inject.css"
        ],
        "js": [
            "scripts/inject.js"
          ],
        "run_at": "document_end",
        "all_frames": false
    }
],
"web_accessible_resources": [
    "frame.html"
]

frame.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="css/angular-csp.css" type="screen">
        <title>name</title>
    </head>

  <body>
    <div class="popup" ng-app="popup" ng-csp>
        <div ui-view></div>
    </div>
    <script src="js/jquery/jquery.min.js"></script>
    <script src="js/angular/angular.min.js"></script>
  </body>
</html>

1 个解决方案

#1


You can't do it directly; cross-origin restrictions apply.

你不能直接做;跨性别限制适用。

Instead, you need to message your content script to manipulate/query the page for you.

相反,您需要向内容脚本发送消息,以便为您操作/查询页面。

#1


You can't do it directly; cross-origin restrictions apply.

你不能直接做;跨性别限制适用。

Instead, you need to message your content script to manipulate/query the page for you.

相反,您需要向内容脚本发送消息,以便为您操作/查询页面。