UnhandledPromiseRejectionWarning: TypeError: невозможно использовать оператор in
У меня есть json, который выглядит так:
{"accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","accept-language":"en-US","referer":"https://www.sahibinden.com/en/cars?sorting=date_desc","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.2 Safari/605.1.15","x-origin-dc":"gytp","x-forwarded-proto":"https","x-forwarded-for":"39.41.162.210","x-tls-version":"771","x-client-srcport":"52468","istl-infinite-loop":"1","x-j3popqvx-f":"A1wraNpyAQAAV49ZLH5TS8mT9x5JDpH7WJPlwQNv4h7U5JxYfxEOUa_Z7o5pAScpotL6K1FB4hcAAOfvAAAAAA==","x-j3popqvx-b":"v2j9i8","x-j3popqvx-c":"AIC8ZdpyAQAAovzca2FjGMY3Jtuxj0kootlxgwYXmgR4ysP_sW3w2brE25d3","x-j3popqvx-d":"AAaCxAiBBKCMgcGASZAQgICAACJt8Nm6xNuXd6oclOq4s6T2AswaceOl4XDPiTRAQwvQBLY","x-j3popqvx-z":"q","x-j3popqvx-a":"H0n5x-7ClCL8mvgjZGwp=LFdx5qCaBrVfu_25mQ4xoKcswK-DbK1HOW0SOr-=E0sYFM0NGXM9hrrlbk_7G=0LLC8gtaz6cpfbhcWDiS97Xfhsk6=u9Fn1ji8lEH=nSXTjVmIn6fGygd9rFFKTp3BuPbPf8sxfSgphtwEvssfLyS=8WYWwS3z-zx7hwsSlfsLkMacgb5vH=tJIypfYWPJnT9oCTX=OpxALO6tHqXnwG2qDcDb05Be_JOzN6ZWfuZSJuH6KooV-YQ_ZCg7FJFdzQbkm_66ZWEXWcL=pJ9PWlZeQI6lJHI1py4Dj-r8uKoWczWXeqmGLVnD1cN-3PRohoiCcmn9i1LyEJT5ln41uBeNPYg6_VfJV6BWeTH1PejG3unc1TZbPVfJPqIrrMw0m_JcC5WApCsTz4LpVmPos_1zJiW8TftQDQxEkSwy_PZjB8n_VF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RVe26HkBqDVdWV8LeqljHprvER_DalV5yhgjN1Rq0X=tTYo8QZ00TKdo_V5xLh3woReRfNueZgyDAMfJ40PqA=i9FjtsEGrxjFjCDREJiNce=bG-hFKE7VBc0JYpaJB55k2EjklgdOoKgybqs3X0kLvCqVjVCNlh0dY1evI7xwHdmTqCBB1L5h52g5haRNBfFi=qAQWnbkyyqaywtSSoBuc3fnSViCj_pQuT8fIX70Fow0wV=yew3CX9yCc_NieEtNKskmlqL5YbWaFfvZOxCdnm91mnzehsliKIhv-jScAWR3AKYi1MiQEfl6LsBCld=28KOFB6HDJ=SB91OM1I2z=IHYcGhXwqqB6wMLDkzITJ3hgQFZQmfCrRHPPNtcD=x0uJ6iRRsze9ip9MdXIWovr8b2y7qxn7kbTiMsM-4mW1hSA3VLWX5CiyI2szMLCxTfJMcnqwbFqvawSEvzcu3w72FGWrcSSY0kkgbibkRyDcQYBM_rEjLPs9sYINY1sMEftTSza=mGGxISzB0tcZsveP_bm_RHwPFVZHhrBubAc=AbXJ2u3TiZ64JIm6=fKt3oggI2HJpp3Lkb7f_WXE0R2lXRkW4a44OJ_57V6t6C_7wC_nlPGWpc0GRiS9TulF8TBEkJIMr1_t2Q2FJbP9iiy7IK=VH2e_LlM5jPegm4mY-N9b7k74SWVtfxTgmf1K0vJvIse3bcuzXRJLXVoENlGGDZ4QqQkmd6dEH8z=rCc-o4Ocsw4LkYCKZz4EeYfP"}
Я хочу иметь возможность искать, существует ли ключ в этом json или нет. Я пробую это делать
headers = {}
page.route('**/*', route => {
const request = route.request()
//console.log(request.url(), JSON.stringify(request.headers()));
headers = JSON.stringify(request.headers());
if("x-j3popqvx-a" in headers){
console.log(headers);
}
return route.continue();
});
let pageRes = await page.goto(url);
await page.waitForTimeout(3 * 1000)
await page.unroute("**/*");
Но это дает мне исключение
UnhandledPromiseRejectionWarning: TypeError: Cannot use 'in' operator to search for 'x-j3popqvx-a' in ....
Вот воспроизводимый код;
const { webkit } = require('playwright');
(async () => {
const browser = await webkit.launch();
const context = await browser.newContext();
const page = await context.newPage();
// Log and continue all network requests
headers_u = {}
page.route('**/*', route => {
const request = route.request()
//console.log(request.url(), JSON.stringify(request.headers()));
headers = JSON.stringify(request.headers());
if("x-j3popqvx-a" in headers){
console.log(headers);
}
return route.continue();
});
let url = await page.goto('https://www.sahibinden.com/en/cars?sorting=date_desc');
//console.log("headerw");
//console.log(headers)
await page.waitForTimeout(3 * 1000)
await browser.close();
})();
Это воспроизводимый код, который можно использовать для тестирования.