facebook / memlab

A framework for finding JavaScript memory leaks and analyzing heap snapshots
https://facebook.github.io/memlab/
MIT License
4.43k stars 121 forks source link

Can't switch chrome version #101

Closed nmnmtttt closed 11 months ago

nmnmtttt commented 11 months ago

i want to switch chrome version like this `const { browserInfo } = require("@memlab/core");

// 测试场景的初始url function url() { return "http://127.0.0.1:8888/zh-CN/components/page"; }

browserInfo.setBrowserVersion("83.0.4086.1"); // console.log(browserInfo)

function sleep(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); }

const clickTarget = async (path, page, testTime = 0) => { await sleep(1000); console.log(testTime); if (testTime > 10) return console.warn("超出最大尝试次数 "); try { return await page.click(path); } catch (error) { return await clickTarget(path, page, ++testTime); } };

// 定义可能出现内存泄露的交互 async function action(page) { console.log(page); for (let testCount = 50; testCount >= 0; testCount--) { console.log("开始点击弹窗"); await clickTarget( "#root > div > div.cxd-Layout-body > div > div.Doc-content > div.MDPreview > div > div:nth-child(2) > div > div.Playgroud-preview > div > div > div > div > div > div > div.cxd-Table-contentWrap.table-ping-right.hasHeader.hasFooter > div.cxd-Table-content > table > tbody > tr.is-Highlight.is-current.cxd-Table-tr--odd.cxd-Table-tr--1th > td.fixed-right-first > div > button:nth-child(3)", page ); // await sleep(3000); // console.log("开始点击查看汇总量"); // await clickTarget( // "body > div.amis-dialog-widget.cxd-Modal.cxd-Modal--full.cxd-Modal--1th > div.cxd-Modal-content.in > div.cxd-Modal-body > div > div > div > div.cxd-Tabs-content > div > div > div > div > div > div.cxd-Table-toolbar.cxd-Table-headToolbar > div > div:nth-child(1) > button", // page // ); // await sleep(5000); // console.log("开始关闭查看汇总量"); // await clickTarget( // "body > div.amis-dialog-widget.cxd-Modal.cxd-Modal--full.cxd-Modal--2th > div.cxd-Modal-content.in > div.cxd-Modal-footer > button.cxd-Button.cxd-Button--default", // page // ); await sleep(3000); console.log("开始聚焦输入"); await clickTarget( "body > div.amis-dialog-widget.cxd-Modal.cxd-Modal--full.cxd-Modal--1th > div.cxd-Modal-content.in > div.cxd-Modal-body > div > div > div > div.cxd-Tabs-content > div > div > div > div > div > div.cxd-Table-contentWrap.table-ping-right.hasHeader.hasFooter > div.cxd-Table-content > table > tbody > tr.is-Highlight.is-current.cxd-Table-tr--odd.cxd-Table-tr--1th > td:nth-child(11) > div > div > div > div > div.cxd-Number-input-wrap > input", page ); await sleep(3000); console.log("开始关闭弹窗"); await clickTarget( "body > div.amis-dialog-widget.cxd-Modal.cxd-Modal--full.cxd-Modal--1th > div.cxd-Modal-content.in > div.cxd-Modal-footer > button.cxd-Button.cxd-Button--default", page ); // await sleep(5000); // console.log("开始重新聚焦输入"); // await clickTarget( // "#root > div > div.cxd-Layout-body > div > div.Doc-content > div.MDPreview > div > div:nth-child(2) > div > div.Playgroud-preview > div > div > div > div > div > form > div:nth-child(5) > div > div > div.cxd-TextControl-input > input[type=text]", // page // ); // await sleep(5000); } } // 指定回到交互前状态的方式 async function back(page) { await sleep(3000); console.log("开始关闭弹窗"); await clickTarget( "body > div.amis-dialog-widget.cxd-Modal.cxd-Modal--full.cxd-Modal--1th > div.cxd-Modal-content.in > div.cxd-Modal-footer > button.cxd-Button.cxd-Button--default", page ); await sleep(5000); console.log("开始重新聚焦输入"); await clickTarget( "#root > div > div.cxd-Layout-body > div > div.Doc-content > div.MDPreview > div > div:nth-child(2) > div > div.Playgroud-preview > div > div > div > div > div > form > div:nth-child(5) > div > div > div.cxd-TextControl-input > input[type=text]", page ); await sleep(5000); } module.exports = { action, back, url, browserInfo }; ` but it's doesn.t work.

what should i do

JacksonGL commented 11 months ago

@nmnmtttt MemLab does not support changing the browser version through the browserInfo.setBrowserVersion method, as this is not an open API (not mentioned in the documentation). This method is internally utilized by MemLab for recording the current browser version. By default, MemLab uses the Chromium browser provided by Puppeteer, and the version of this browser is determined by Puppeteer.

If you want to use a specific version of a browser executable that you have downloaded, you can specify it by using the --chromium-binary CLI argument:

memlab run --scenario scenario.js --chromium-binary path_to_Chrome_binary
nmnmtttt commented 11 months ago

@nmnmtttt MemLab does not support changing the browser version through the browserInfo.setBrowserVersion method, as this is not an open API (not mentioned in the documentation). This method is internally utilized by MemLab for recording the current browser version. By default, MemLab uses the Chromium browser provided by Puppeteer, and the version of this browser is determined by Puppeteer.

If you want to use a specific version of a browser executable that you have downloaded, you can specify it by using the --chromium-binary CLI argument:

memlab run --scenario scenario.js --chromium-binary path_to_Chrome_binary

thanks ,it‘s work