添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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 connect , ExtensionTransport , } from 'puppeteer-core/lib/esm/puppeteer/puppeteer-core-browser.js' ; const tab = await chrome . tabs . create ( { url , } ) ; const browser = await connect ( { transport : await ExtensionTransport . connectTab ( tab . id ) , } ) ; const [ page ] = await browser . pages ( ) ; const target = await page . createCDPSession ( ) ; // try to get the CDPSession. browser . disconnect ( ) ;

Background

Running Puppeteer in Chrome extensions.

Expectation

Get the CDPSession.

Reality

When const target = await page.createCDPSession(); runs, it fails and fires the log below.

// error log for `const target = await page.createCDPSession();`
puppeteer:protocol:SEND ►: {"method":"Target.attachToTarget","params":{"targetId":"pageTargetId","flatten":true},"id":5}
puppeteer:protocol:RECV ◀: {"id":5,"sessionId":"pageTargetSessionId","method":"Target.attachToTarget","error":{"message":"{\"code\":-32000,\"message\":\"Not allowed\"}"}}

I also notice a error log befor it , I don't know if it's relevant.

puppeteer:protocol:SEND ►: {"method":"Runtime.runIfWaitingForDebugger","id":2,"sessionId":"tabTargetSessionId"}
// omit some logs
puppeteer:protocol:RECV ◀: {"id":2,"sessionId":"tabTargetSessionId","method":"Runtime.runIfWaitingForDebugger","error":{"message":"{\"code\":-32001,\"message\":\"Session with given id not found.\"}"}}
puppeteer:error: ProtocolError: Protocol error (Runtime.runIfWaitingForDebugger): {"code":-32001,"message":"Session with given id not found."}
    at <instance_members_initializer> (CallbackRegistry.js:89:14)
    at new Callback (CallbackRegistry.js:93:16)
    at CallbackRegistry.create (CallbackRegistry.js:19:26)
    at Connection._rawSend (Connection.js:86:26)
    at CdpCDPSession.send (CDPSession.js:63:33)
    at #onAttachedToTarget (ChromeTargetManager.js:283:21)
    at listener (ChromeTargetManager.js:123:42)
    at mitt.js:36:7
    at Array.map (<anonymous>)
    at Object.emit (mitt.js:35:20)

Puppeteer configuration file (if used)

No response

Puppeteer version

23.6.1

Node version

20.18.0

Package manager

Package manager version

9.12.2

Operating system

Windows