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

Can't retrieve IFrame in {headless: false} mode #4964

Closed
pahan35 opened this issue Sep 23, 2019 · 6 comments
Closed

Can't retrieve IFrame in {headless: false} mode #4964

pahan35 opened this issue Sep 23, 2019 · 6 comments

Comments

@pahan35
Copy link

pahan35 commented Sep 23, 2019

Steps to reproduce

  1. Take prepared repository https://github.com/pahan35/puppeteer-stripe-iframe-detection-bug
  2. Install packages npm i
  3. Run npm start

Tell us about your environment:

What steps will reproduce the problem?

const puppeteer = require('puppeteer')
const {Events} = require('puppeteer/lib/Events')

;(async () => {
  const browser = await puppeteer.launch({
    headless: false,
  })

  const page = await browser.newPage()

  const waitForFrame = async name => {
    const frames = new Set()
    return new Promise((resolve, reject) => {
      const wait = setTimeout(() => {
        reject(
          Error(
            `Timeout while waiting for frame "${name}", have: ${JSON.stringify(
              [...frames],
            )}`,
          ),
        )
      }, 10000)

      function checkFrame() {
        const frame = page.frames().find(f => {
          const fname = f.name()
          frames.add(fname)
          return fname.includes(name)
        })
        if (frame) {
          clearTimeout(wait)
          resolve(frame)
        } else {
          page.once(Events.Page.FrameNavigated, checkFrame)
        }
      }

      checkFrame()
    })
  }

  await page.goto('https://stripe-payments-demo.appspot.com')

  try {
    const stripeFrame = await waitForFrame('privateStripeFrame')
    await stripeFrame.waitFor('body')
    console.log('Body found successfully')
  } catch (e) {
    console.error(e)
  }
  process.exit()
})()
  1. Just run code above

What is the expected result?
I expect to see Body found successfully from script, as it works in headless: true mode

What happens instead?
Puppeteer fails on retrieving iframe

Extra info is described in README.MD of the linked repo

@tshmit
Copy link

tshmit commented Sep 28, 2019

pahah, check out #4960

@stale
Copy link

stale bot commented Jun 27, 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 Jun 27, 2022
@pahan35
Copy link
Author

pahan35 commented Jun 27, 2022

pahah, check out #4960

Thanks. Both variants work for me.

  const browser = await puppeteer.launch({
    headless: true,
    args: ['--disable-features=site-per-process'],
  })

or

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

@stale stale bot removed the unconfirmed label Jun 27, 2022
@stale
Copy link

stale bot commented Aug 30, 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 Aug 30, 2022
@OrKoN
Copy link
Collaborator

OrKoN commented Sep 5, 2022

That should work in the latest version, I believe. Please open a new issue if it still reproduces.

@OrKoN OrKoN closed this as completed Sep 5, 2022
@salahbm
Copy link

salahbm commented Jan 2, 2024

Facing same error with new headless: 'new'. If headlessL false it is working without any erros, however if I enable the headless more it can not find the iframe : (

  const browser = await puppeteer.launch({ headless: 'new' });
  const page = await browser.newPage();
  await page.setViewport({ width: 1920, height: 1080 });
  await page.goto("https://map.naver.com/v5/search/" + searchName);
  await wait(1);

  let frame: any | null;
  const timer = setTimeout(() => {
    browser.close();
  }, 5000);
  try {
    await page.waitForSelector("#entryIframe", { timeout: 30000 });

    const iframeHandle: any | null = await page.$("#entryIframe");
    if (!iframeHandle) {
      throw new Error("iframe element not found.");
    }

    frame = await iframeHandle.contentFrame();
    clearTimeout(timer);
  } catch {
    console.log(searchName + " iframe not found.");
    browser.close();
    return;
  }

  await wait(2);

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

4 participants