[英]How can I use session storage in a Puppeteer script?
I am trying to collect the encounter id from a Puppeteer script that opens a browser.我正在尝试从打开浏览器的 Puppeteer 脚本中收集遭遇 ID。 I run these scripts in AWS synthetic canaries.
我在 AWS 合成金丝雀中运行这些脚本。 It does not run, the error reads:
它没有运行,错误显示:
sessionStorage is not defined Stack
sessionStorage 未定义堆栈
This is the code I use这是我使用的代码
let data = sessionStorage.getItem('aw-encounter-id');
The browser (Puppeteer) needs to support sessionStorage.浏览器(Puppeteer)需要支持 sessionStorage。 This article may help:
这篇文章可能会有所帮助:
https://newbedev.com/puppeteer-how-to-store-a-session-including-cookies-page-state-local-storage-etc-and-continue-later https://newbedev.com/puppeteer-how-to-store-a-session-including-cookies-page-state-local-storage-etc-and-continue-later
According to that, it might work if you initialize passing a data dir:据此,如果您初始化传递数据目录,它可能会起作用:
puppeteer.launch({userDataDir: '/tmp/myChromeSession'});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.