Skip to content

Cannot get page content using puppeteer ? #365

@geminigeek

Description

@geminigeek

hi,

i am trying to get page content/html but i am getting error Error [ReferenceError]: XMLSerializer is not defined

i am using docker for running the script, from inside docker i can dump the content of url with command line usage

EDIT: i tried same code with "cloud.lightpanda.io" its also not working using browser=lightpanda

my code

import puppeteer from "puppeteer-core"
let url = "https://www.wikipedia.org/"

// use browserWSEndpoint to pass the Lightpanda's CDP server address.
const browser = await puppeteer.connect({
  browserWSEndpoint: "ws://127.0.0.1:9222",
})

// The rest of your script remains the same.
const context = await browser.createBrowserContext()
const page = await context.newPage()

await page.goto(url)

const html = await page.content()
console.log("html :>> ", html)

await page.close()
await context.close()
await browser?.disconnect()

error

node:internal/modules/run_main:122
    triggerUncaughtException(
    ^

Error [ReferenceError]: XMLSerializer is not defined
    at  ( at CdpFrame.<anonymous> (file:///root/lightpanda-docker/using-light-panda/node_modules/.pnpm/[email protected]/node_modules/puppeteer-core/lib/esm/puppeteer/util/decorators.js:101:27), <anonymous>:8:43)
    at #evaluate (file:///root/lightpanda-docker/using-light-panda/node_modules/.pnpm/[email protected]/node_modules/puppeteer-core/lib/esm/puppeteer/cdp/ExecutionContext.js:387:19)
    at async ExecutionContext.evaluate (file:///root/lightpanda-docker/using-light-panda/node_modules/.pnpm/[email protected]/node_modules/puppeteer-core/lib/esm/puppeteer/cdp/ExecutionContext.js:274:16)
    at async IsolatedWorld.evaluate (file:///root/lightpanda-docker/using-light-panda/node_modules/.pnpm/[email protected]/node_modules/puppeteer-core/lib/esm/puppeteer/cdp/IsolatedWorld.js:97:16)
    at async CdpFrame.evaluate (file:///root/lightpanda-docker/using-light-panda/node_modules/.pnpm/[email protected]/node_modules/puppeteer-core/lib/esm/puppeteer/api/Frame.js:345:20)
    at async CdpFrame.content (file:///root/lightpanda-docker/using-light-panda/node_modules/.pnpm/[email protected]/node_modules/puppeteer-core/lib/esm/puppeteer/api/Frame.js:574:20)
    at async CdpPage.content (file:///root/lightpanda-docker/using-light-panda/node_modules/.pnpm/[email protected]/node_modules/puppeteer-core/lib/esm/puppeteer/api/Page.js:555:20)
    at async file:///root/lightpanda-docker/using-light-panda/error.mjs:15:14

Node.js v22.11.0

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions