muralikg / puppetcam

Export puppeteer tab as webm video
MIT License
322 stars 62 forks source link

How do I instruct screen to start recording in the export file #16

Closed JamesBotterill closed 4 years ago

JamesBotterill commented 4 years ago

I would like to be able to send the record screen event only after I've done a number of actions within my export.js file.

How would I go about this?

muralikg commented 4 years ago

There is a message to start recording in content_script.js of the chrome extension. https://github.com/muralikg/puppetcam/blob/df12a68c51e1480cd32def6d841f123edbb8adfa/content_script.js#L22

Remove that from the plugin, which is posting the message on window.load and do it when your page is ready for recording.

muralikg commented 4 years ago

@JamesBotterill Feel free to reopen the issue if you have any issues

JamesBotterill commented 4 years ago

@muralikg I've been trying this approach but so far been unable for it to work.

do I need to pass it through using a puppeteer api call?

muralikg commented 4 years ago

Yes, it should be from within page.evaluate API

await page.evaluate(function(){
  window.postMessage({ type: 'REC_CLIENT_PLAY', data: { url: window.location.origin } }, '*') 
})
JamesBotterill commented 4 years ago

this is the same issue as I was running into before, it looks like when you evaluate from within the page the share a tab dialog appears and as such the promise is never resolved and the app sticks.

Trying to find a chromium flag to disable this dialog if possible.

muralikg commented 4 years ago

When you start recording the document title has to be set to 'puppetcam` to avoid the permission dialog box. Can you try with this.

await page.evaluate(function(){
  document.title = 'puppetcam'
  window.postMessage({ type: 'REC_CLIENT_PLAY', data: { url: window.location.origin } }, '*') 
})
JamesBotterill commented 4 years ago

that resolved it, I didn't think I need to reset it as it's called from within the content script.

Thanks,

James

muralikg commented 4 years ago

Document title could be overwritten by some other means on that page (probably by other javascript on that page). Anyways glad it worked for you.