Vladislav moroz
Vladislav moroz

Reputation: 21

Access to alien iframe in chrome extensions on the example of imacros and selenium ide

I'm writing a chrome extension and I'm having trouble accessing an iframe. I ended up googling this issue and all I got was "security policy" and why the iframe can't be accessed. In manifest.json "all_frames": true does not help:

    "permissions": ["tabs","storage","<all_urls>","activeTab"],  
    "content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": ["content.js", "raschet.js"],
      "run_at": "document_end",
      "all_frames": true
    }
    ],

I found a way to disable web security when turning on the browser: --disable-web-security(+ other settings). If we do this and go to the site with recaptcha https://www.google.com/recaptcha/api2/demo, after can use the code to click on the captcha:

document.querySelectorAll("iframe")[0].contentDocument.querySelectorAll("div[class='recaptcha-checkbox-border']")[0].click()

Yes it works, but disabling security is not my option. There are programs for automating work in the browser iMacros and Selenium IDE. These are also extensions with javascript and here they were able to realize focus and click on the iframe. Exampele iMacros:

FRAME F=1
TAG POS=1 TYPE=DIV ATTR=CLASS:recaptcha-checkbox-border&&ROLE:presentation&&TXT:

Exampele Selenium IDE:

command: select frame    target: index=0
command: click           target: css=.recaptcha-checkbox-border

Is it possible to repeat the same in my extension using JS or Jquery?

Upvotes: 0

Views: 292

Answers (0)

Related Questions