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

puppeteer-har package does not record third party cookies. #52

Open
simonft opened this issue Jun 7, 2023 · 0 comments
Open

puppeteer-har package does not record third party cookies. #52

simonft opened this issue Jun 7, 2023 · 0 comments

Comments

@simonft
Copy link
Contributor

simonft commented Jun 7, 2023

From Surya:
Solution:

// Returns map of request ID to raw CDP request data. This will be populated as requests are made.
// See: https://itecnote.com/tecnote/missing-request-headers-in-puppeteer/
async function setupLoggingOfAllNetworkData(page) {
  const cdpSession = await page.target().createCDPSession();
  await cdpSession.send("Network.enable");
  const cdpRequestDataRaw = {};
  const addCDPRequestDataListener = (eventName) => {
    cdpSession.on(eventName, (request) => {
      cdpRequestDataRaw[request.requestId] =
        cdpRequestDataRaw[request.requestId] || {};
      Object.assign(cdpRequestDataRaw[request.requestId], {
        [eventName]: request,
      });
    });
  };
  addCDPRequestDataListener("Network.requestWillBeSent");
  addCDPRequestDataListener("Network.requestWillBeSentExtraInfo");
  addCDPRequestDataListener("Network.responseReceived");
  addCDPRequestDataListener("Network.responseReceivedExtraInfo");
  return cdpRequestDataRaw;
}

and then const cdpRequestDataRaw = await setupLoggingOfAllNetworkData(page);
and then you can merge them back into the har file from the package
the request ids match

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant