我使用以下代码:
getLocalStorage = async function(page, data = {}) {
// based on https://stackoverflow.com/a/54355801/1407622
const client = page._client;
for (const frame of page.frames()) {
// it is unclear when the following url values occur:
// potentially about:blank is the frame before the very first page is browsed
if(!frame.url().startsWith('http')) continue; // filters chrome-error://, about:blank and empty url
const securityOrigin = new url.URL(frame.url()).origin;
const response = await client.send('DOMStorage.getDOMStorageItems',
{ storageId: { isLocalStorage: true, securityOrigin } },
);
if (response.entries.length > 0) {
let entries = {};
for (const [key,val] of response.entries) {
entries[key] = {
value: safeJSONParse(val),
};
}
// console.log(response.entries);
data[securityOrigin] = Object.assign({}, data[securityOrigin], entries);
}
}
return data;
};
来源:https
://github.com/EU-EDPS/website-evidence-collector/blob/master/lib/tools.js
原始 SA 来源:使用 Puppeteer 从 localStorage 获取所有值
但是,有时我会收到相同的错误:“找不到给定安全来源的框架”