-
Consider following code: {
"type": "module",
"dependencies": {
"crawlee": "3.1.4",
"playwright": "1.27.1"
}
} import { chromium } from "playwright"
console.log("Scraping server ip addresses using playwright only")
const browser = await chromium.launch()
const context = await browser.newContext()
const page = await context.newPage()
const session = await context.newCDPSession(page)
await setupResponseIpLogging(session)
await page.goto("https://google.de")
await browser.close()
console.log("Scraping server ip addresses using crawlee playwright crawler")
import { PlaywrightCrawler, RequestQueue } from "crawlee"
const navigationQueue = await RequestQueue.open()
await navigationQueue.addRequest({ url: "https://google.de" })
const crawler = new PlaywrightCrawler({
requestQueue: navigationQueue,
preNavigationHooks: [
async ctx => {
const context = ctx.page.context()
const session = await context.newCDPSession(ctx.page)
await setupResponseIpLogging(session)
}
],
requestHandler: () => { }
})
await crawler.run()
process.exit()
async function setupResponseIpLogging(session) {
session.on("Network.responseReceived", (event) => {
const ip = event.response.remoteIPAddress
if (ip) console.log(ip)
})
await session.send("Network.enable")
} This (
Obviously something in the engine is kind of masking the remote IP addresses, so that they always point to localhost. Does anybody have an idea how to stop it from doing that? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Probably this, but I don't recall the reason from the top of my head. |
Beta Was this translation helpful? Give feedback.
-
Is there any plan to address this or provide an option to preserve the original values? I’d suggest creating an issue for it since it might be important for those relying on accurate CDP logs. |
Beta Was this translation helpful? Give feedback.
Probably this, but I don't recall the reason from the top of my head.
https://github.com/apify/crawlee/blob/master/packages/browser-pool/src/playwright/playwright-plugin.ts#L48-L52