Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to access cross domain iframes when not headless #4960

Closed
tshmit opened this issue Sep 21, 2019 · 10 comments
Closed

Unable to access cross domain iframes when not headless #4960

tshmit opened this issue Sep 21, 2019 · 10 comments

Comments

@tshmit
Copy link

tshmit commented Sep 21, 2019

After updating to v1.20 I'm unable to access iframes from a foreign domain with headless: false.

Here's a page with 4 iframes, 3 of which are cross domain:

<html>
<body>
<iframe src="https://en.wikipedia.org/wiki/IFrame"></iframe>
<iframe src="http://example.com/"></iframe>
<iframe srcdoc="<p>Frame [2]</p>"></iframe>
<iframe src="http://www.htmlhelp.com/reference/html40/special/iframe.html"></iframe>
</body>
</html>

And some code that tries to access the frames:

const puppeteer = require('puppeteer');
(async () => {
    const browser = await puppeteer.launch({ headless: false });
    const [page] = await browser.pages();
    await page.goto('http://localhost: ... ');

    console.log('childFrames count:', page.mainFrame().childFrames().length);
    console.log('pageFrames count:', page.frames().length);

    const iframeHandles = await page.$$('iframe');

    console.log('contentFrame[0] is valid:', await iframeHandles[0].contentFrame() !== null);
    console.log('contentFrame[2] is valid:', await iframeHandles[2].contentFrame() !== null);

    await browser.close();
})();

Output with headless false:

childFrames count: 1
pageFrames count: 2
contentFrame[0] is valid: false
contentFrame[2] is valid: true

Output with headless true:

childFrames count: 4
pageFrames count: 9
contentFrame[0] is valid: true
contentFrame[2] is valid: true

What is the expected result?
I'd expect to be able to access cross domain iframes whether running headless or not (this was the case as of ~v1.15) Am I missing something?

@taeyoung4808
Copy link

same problem here !

@hi-ogawa
Copy link

It seems some workaround is already discussed here #2548 (comment) and it worked for me.

@tshmit
Copy link
Author

tshmit commented Sep 27, 2019

Thanks for your reply, @hi-ogawa.
You're right --disable-features=site-per-process does seem to fix the problem.

I'm perplexed as to why my code ran without flag until updating to 1.20, but that's ok, I'll take it! :-)

@jiriyao
Copy link

jiriyao commented Oct 11, 2019

--disable-features=site-per-process does seem to fix the problem.
but my chormium is crashed by add this item when handless is false

@ClockRide
Copy link

Doesn't work for me. It's fucking disgusting!

@flashjames
Copy link

The correct args are:

await puppeteer.launch({headless: headless, devtools: true, args: ['--disable-web-security', '--disable-features=IsolateOrigins', ' --disable-site-isolation-trials']});

But puppeteer kept crashing.

The reason was that I used an old puppeteer version, puppeteer 1.8.0.
After upgrading to puppeteer@8.0.0, it works.

You can check that isolation is disabled in:
chrome://process-internals

Suggested in https://stackoverflow.com/a/51320323/337587

More information on the flag: https://www.chromium.org/Home/chromium-security/site-isolation

@tshmit I suggest you close this issue, since it fixed in some version since you had the problem.

@8m0
Copy link

8m0 commented May 2, 2022

You don't even understand how sexy you are

The correct args are:

@stale
Copy link

stale bot commented Jul 1, 2022

We're marking this issue as unconfirmed because it has not had recent activity and we weren't able to confirm it yet. It will be closed if no further activity occurs within the next 30 days.

@stale stale bot added the unconfirmed label Jul 1, 2022
@stale
Copy link

stale bot commented Jul 31, 2022

We are closing this issue. If the issue still persists in the latest version of Puppeteer, please reopen the issue and update the description. We will try our best to accomodate it!

@stale stale bot closed this as completed Jul 31, 2022
@TheGP
Copy link

TheGP commented Apr 6, 2024

According to ChatGPT and my testing, this is what actually works:

.\chrome.exe --disable-site-isolation-trials

Then, when you go to chrome://process-internals/#site-isolation you will see Site Isolation mode: Disabled. Yay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants