Does Chromium support intercept WebWorker requests via CDP?
Asked Answered
F

0

6

I'm trying to intercept WebWorker requests by sending Fetch.enable in a worker target session, but got a "'Fetch.enable' wasn't found" error from Chromium. Does that mean Chromium not support WebWorker request interception? My Chromium version is 97.0.4691.0 (Developer Build).

A reasonable answer would be greatly appreciated.

--Update-- I guess I've got it worked in the puppeteer way. Please check out my fix kitt1987/puppeteer. Just a quick fix, not well-designed.

TL;NR

Actually, I intercepted requests of a website using puppeteer. Then I found that this site requests some files in WebWorker but puppeteer has bugs if the interception is enabled. See puppeteer/puppeteer#4208 and puppeteer/puppeteer#2781.

After digging in puppeteer source code and tracing raw protocol messages, it seems that calling page.setRequestInterception(true) also intercepts WebWorker requests, but these requests never issue any Network.requestWillBeSent events, which is known as page.request events in puppeteer, then WebWorker requests hang for waiting for a request.continue() which is usually called in the page.request event handler.

Then I tried to figure out why Network.requestWillBeSent events were lost. Chrome DevTools is able to trace all requests in its network panel, then I analyzed its CDP traffic in Protocol Monitor and found that a new WebWorker started a new session, it needs to send Network.enable again in the new session to enable network tracing. But, after I send Fetch.enable in the new session to enable interception, the error arose.

  puppeteer:protocol:SEND ► {"sessionId":"3DE89BAC041203C90EF1B3D2CC348EAA","method":"Fetch.enable","params":{"handleAuthRequests":true,"patterns":[{"urlPattern":"*"}]},"id":245} +0ms
  puppeteer:protocol:RECV ◀ {"id":245,"error":{"code":-32601,"message":"'Fetch.enable' wasn't found"},"sessionId":"3DE89BAC041203C90EF1B3D2CC348EAA"} +0ms

You can find my fix in kitt1987/puppeteer.

Filomena answered 9/1, 2022 at 21:29 Comment(2)
Having the same issue. I was able to listen to Target.attachedToTarget and in this I send a command Network.enable to the targetId came from this event. but I still see the same behavior where Network.requestWillBeSent is not showing.Rusert
Maybe Selenium-Interceptor helps you as a starting point :)Machinegun

© 2022 - 2024 — McMap. All rights reserved.