cyrus-and / chrome-har-capturer

Capture HAR files from a Chrome instance
MIT License
535 stars 90 forks source link

Question: how to save the screenshot along with the har-file #89

Closed jsw-zorro closed 3 years ago

jsw-zorro commented 3 years ago

Thanks for your previous help. The tool actually helps me a lot. Right now, I want to add the screenshot for each website, when they are finished loading. So I can check whether they have been loaded successfully or not. And I have read about the #66, however, as I am new to JS. I am a little bit confused about the points you have discussed. You have suggested to use the async function postHook(url, client) { const tempReturn = new Promise((fulfill, reject) => { setTimeout(fulfill, program.grace || 0); }); const {data} = await client.Page.captureScreenshot(); fs.writeFileSync('/tmp/screenshot.png', Buffer.from(data, 'base64')); return tempReturn; } to deal with it. I am wondering, shall I just use this paragraph of code to replace the generatePostHook function? Or I can just copy and paste it in the client.js?

cyrus-and commented 3 years ago

It all depends on your specific goal, ideally since this is also a library you should be able to write your own program that requires 'chrome-har-capturer', basically an ad hoc version of cli.js with only the features you want, specifically the ability to take screenshot.

Most of the command options have their counterpart in the API, those who have not it means that they're implemented in client.js via hooks.

jsw-zorro commented 3 years ago

Thanks for the response. I modified the client.js and reinstall the package. And it works. Thanks!