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

the example used in the readme does not work #379

Open
frankgreco opened this issue Jan 24, 2025 · 4 comments
Open

the example used in the readme does not work #379

frankgreco opened this issue Jan 24, 2025 · 4 comments
Assignees
Labels
bug Something isn't working CDP Chrome Debug Protocol

Comments

@frankgreco
Copy link

The hello world example does not work. In fact, no website I've tried works. It's usually always panics.

./lightpanda-aarch64-macos --host 127.0.0.1 --port 9222
info(websocket): starting blocking worker to listen on 127.0.0.1:9222
info(server): accepting new conn...
info(server): client connected
info(browser): GET https://wikipedia.com/ 200
info(browser): fetch [https://wikipedia.com/portal/wikipedia.org/assets/js/index-2...](https://wikipedia.com/portal/wikipedia.org/assets/js/index-24c3e2ca18.js): http.Status.ok
info(browser): eval script portal/wikipedia.org/assets/js/index-24c3e2ca18.js: ReferenceError: location is not defined
info(browser): fetch [https://wikipedia.com/portal/wikipedia.org/assets/js/gt-ie9-...](https://wikipedia.com/portal/wikipedia.org/assets/js/gt-ie9-ce3fe8e88d.js): http.Status.ok
error(events): event handler error: error.JSExecCallback
info(events): event handler error try catch: TypeError: Cannot read properties of undefined (reading 'length')
info(server): close cmd, closing conn...
info(server): accepting new conn...
thread 5274880 panic: attempt to use null value
zsh: abort ./lightpanda-aarch64-macos --host 127.0.0.1 --port 9222
@krichprollsch krichprollsch self-assigned this Jan 25, 2025
@krichprollsch krichprollsch added bug Something isn't working CDP Chrome Debug Protocol labels Jan 25, 2025
@krichprollsch
Copy link
Member

Hello @frankgreco,
Thanks for the issue.
Indeed I can reproduce, something goes wrong on handling the client's disconnection.

But I get the list of the links correctly. Did you get them?

@frankgreco
Copy link
Author

frankgreco commented Jan 25, 2025

If I try to dump the page contents, I get a different error.

'use strict'

import puppeteer from 'puppeteer-core';

const browser = await puppeteer.connect({
  browserWSEndpoint: "ws://127.0.0.1:9222",
});

const context = await browser.createBrowserContext();
const page = await context.newPage();

await page.goto('https://wikipedia.com/');

console.log(await page.content());

await page.close();
await context.close();
❯ node index.mjs
file:///Users/frank/projects/superblocks/browser/node_modules/puppeteer-core/lib/esm/puppeteer/common/CallbackRegistry.js:77
            this._reject(callback, new TargetCloseError('Target closed'));
                                   ^

TargetCloseError: Protocol error (Runtime.callFunctionOn): Target closed
    at CallbackRegistry.clear (file:///Users/frank/projects/superblocks/browser/node_modules/puppeteer-core/lib/esm/puppeteer/common/CallbackRegistry.js:77:36)
    at CdpCDPSession._onClosed (file:///Users/frank/projects/superblocks/browser/node_modules/puppeteer-core/lib/esm/puppeteer/cdp/CDPSession.js:106:25)
    at #onClose (file:///Users/frank/projects/superblocks/browser/node_modules/puppeteer-core/lib/esm/puppeteer/cdp/Connection.js:171:21)
    at WebSocket.<anonymous> (file:///Users/frank/projects/superblocks/browser/node_modules/puppeteer-core/lib/esm/puppeteer/node/NodeWebSocketTransport.js:43:30)
    at callListener (/Users/frank/projects/superblocks/browser/node_modules/ws/lib/event-target.js:290:14)
    at WebSocket.onClose (/Users/frank/projects/superblocks/browser/node_modules/ws/lib/event-target.js:220:9)
    at WebSocket.emit (node:events:520:28)
    at WebSocket.emitClose (/Users/frank/projects/superblocks/browser/node_modules/ws/lib/websocket.js:272:10)
    at Socket.socketOnClose (/Users/frank/projects/superblocks/browser/node_modules/ws/lib/websocket.js:1341:15)
    at Socket.emit (node:events:520:28) {
  cause: ProtocolError
      at <instance_members_initializer> (file:///Users/frank/projects/superblocks/browser/node_modules/puppeteer-core/lib/esm/puppeteer/common/CallbackRegistry.js:97:14)
      at new Callback (file:///Users/frank/projects/superblocks/browser/node_modules/puppeteer-core/lib/esm/puppeteer/common/CallbackRegistry.js:101:16)
      at CallbackRegistry.create (file:///Users/frank/projects/superblocks/browser/node_modules/puppeteer-core/lib/esm/puppeteer/common/CallbackRegistry.js:20:26)
      at Connection._rawSend (file:///Users/frank/projects/superblocks/browser/node_modules/puppeteer-core/lib/esm/puppeteer/cdp/Connection.js:89:26)
      at CdpCDPSession.send (file:///Users/frank/projects/superblocks/browser/node_modules/puppeteer-core/lib/esm/puppeteer/cdp/CDPSession.js:66:33)
      at #evaluate (file:///Users/frank/projects/superblocks/browser/node_modules/puppeteer-core/lib/esm/puppeteer/cdp/ExecutionContext.js:359:50)
      at ExecutionContext.evaluate (file:///Users/frank/projects/superblocks/browser/node_modules/puppeteer-core/lib/esm/puppeteer/cdp/ExecutionContext.js:274:36)
      at IsolatedWorld.evaluate (file:///Users/frank/projects/superblocks/browser/node_modules/puppeteer-core/lib/esm/puppeteer/cdp/IsolatedWorld.js:97:30)
      at CdpFrame.evaluate (file:///Users/frank/projects/superblocks/browser/node_modules/puppeteer-core/lib/esm/puppeteer/api/Frame.js:345:43)
      at CdpFrame.<anonymous> (file:///Users/frank/projects/superblocks/browser/node_modules/puppeteer-core/lib/esm/puppeteer/util/decorators.js:101:27)
}

Node.js v22.6.0
❯ ./lightpanda-aarch64-macos --host 127.0.0.1 --port 9222
info(websocket): starting blocking worker to listen on 127.0.0.1:9222
info(server): accepting new conn...
info(server): client connected
info(browser): GET https://wikipedia.com/ 200
info(browser): fetch https://wikipedia.com/portal/wikipedia.org/assets/js/index-24c3e2ca18.js: http.Status.ok
info(browser): eval script portal/wikipedia.org/assets/js/index-24c3e2ca18.js: ReferenceError: location is not defined
info(browser): fetch https://wikipedia.com/portal/wikipedia.org/assets/js/gt-ie9-ce3fe8e88d.js: http.Status.ok
error(events): event handler error: error.JSExecCallback
info(events): event handler error try catch: TypeError: Cannot read properties of undefined (reading 'length')
info(server): close cmd, closing conn...
info(server): accepting new conn...
thread 5774907 panic: attempt to use null value
zsh: abort      ./lightpanda-aarch64-macos --host 127.0.0.1 --port 9222

@sanjomathew09
Copy link

'use strict';

import puppeteer from 'puppeteer-core';

async function main() {
try {
// Connect to the browser instance
const browser = await puppeteer.connect({
browserWSEndpoint: 'ws://127.0.0.1:9222', // WebSocket endpoint
});

// Create a new browser context (isolation)
const context = await browser.createIncognitoBrowserContext(); // Use incognito mode for a clean session

// Open a new page in the context
const page = await context.newPage();

// Navigate to the target URL
await page.goto('https://wikipedia.com/', {
  waitUntil: 'networkidle2', // Wait for network to be idle
});

// Extract the page content
const pageContent = await page.content();
console.log(pageContent);

// Clean up
await page.close(); // Close the page
await context.close(); // Close the browser context
await browser.disconnect(); // Disconnect from the browser

} catch (error) {
console.error('An error occurred:', error);
}
}

main();

@ManojBhamsagar-Draup
Copy link

ManojBhamsagar-Draup commented Jan 29, 2025

Yes I'm also stuck with the same error:

const context = await browser.createBrowserContext();
^

TypeError: browser.createBrowserContext is not a function

At least, please provide a minimal example that works. Since this repo lacks documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working CDP Chrome Debug Protocol
Projects
None yet
Development

No branches or pull requests

4 participants