Warm tip: This article is reproduced from serverfault.com, please click

Puppeteer iframe contentFrame returns null

发布于 2020-11-28 12:24:17

I have an interesting puppeteer problem that I'm not sure how to solve.

I have a webpage with an iframe on it. To get the iframe handle I do the following:

const iframeHandle = await page.$('iframe')

To get the contentFrame I simply run:

const frame = await iframeHandle.contentFrame()

However, this returns null.

I printed out the iframeHandle to make sure I got the correct element, and it does grab the correct iframe:

console.dir(iframeHandle)
 _remoteObject: {
    type: 'object',
    subtype: 'node',
    className: 'HTMLIFrameElement',
    description: 'iframe',
    objectId: '{"injectedScriptId":5,"id":6}'
  },

Does anyone know how I can get the content of the iframe?

Questioner
Dirk Hoekstra
Viewed
0
Ilya Shevyryaev 2020-12-29 17:14:14

The problem is with browser startup options. Add the following to "args":

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