Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move more of video capture into browser automations #23587

Merged
merged 17 commits into from
Aug 31, 2022

Conversation

flotwig
Copy link
Contributor

@flotwig flotwig commented Aug 29, 2022

  • Closes

User facing changelog

n/a

Additional details

Steps to test

How has the user experience changed?

PR Tasks

  • Have tests been added/updated?
  • [na] Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • [na] Has a PR for user-facing changes been opened in cypress-documentation?
  • [na] Have API changes been updated in the type definitions?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Aug 29, 2022

Thanks for taking the time to open a PR!

@flotwig flotwig marked this pull request as ready for review August 29, 2022 14:13
@tbiethman tbiethman self-requested a review August 29, 2022 15:43
Base automatically changed from browser-types to develop August 29, 2022 19:47
@cypress
Copy link

cypress bot commented Aug 29, 2022



Test summary

39665 0 3345 0Flakiness 2


Run details

Project cypress
Status Passed
Commit e1b7791
Started Aug 31, 2022 6:39 PM
Ended Aug 31, 2022 6:55 PM
Duration 15:33 💡
OS Linux Debian - 11.3
Browser Multiple

View run in Cypress Dashboard ➡️


Flakiness

commands/cookies.cy.ts Flakiness
1 cy.origin cookies > client side > .getCookie(), .getCookies(), and .setCookie()
spec_bridge.cy.ts Flakiness
1 visits foobar.com and types foobar inside an input

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

Copy link
Contributor

@tbiethman tbiethman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a nice refactor. I double checked the recordings for this branch on the dashboard, everything is still functional.

async startVideoRecording (writeVideoFrame: WriteVideoFrame, screencastOpts?) {
this.onFn('Page.screencastFrame', async (e) => {
writeVideoFrame(Buffer.from(e.data, 'base64'))
await this.sendDebuggerCommandFn('Page.screencastFrameAck', { sessionId: e.sessionId })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async function() { await Promise() } is mostly equivalent to function() { return Promise() }. You only need to await things if you want flow control to return to this function after a promise completes (eg, to return a different value than the inner promise resolves to).

Same with the outer startVideoRecording as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean, but I prefer it this way, since I don't want to "return" any value. A synchronous function wouldn't return on this line either. Absent of a coding style guide, there's a mix of both ways in the codebase.

packages/server/lib/browsers/chrome.ts Show resolved Hide resolved
return automation.use(cdpAutomation)
automation.use(cdpAutomation)

return cdpAutomation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(for comparison, this is a good use of async/await, because we want to call a method on cdpAutomation after the first promise resolves)


await pageCriClient.send('Page.enable')

await options.onInitializeNewBrowserTab?.()
await options['onInitializeNewBrowserTab']?.()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It bypasses type checks on options, otherwise you get: Property 'onInitializeNewBrowserTab' does not exist on type 'BrowserLaunchOpts | BrowserNewTabOpts'. since it's only on one of the two.

Open to suggestions on a cleaner way to do this... await (options as BrowserNewTabOpts).onInitializeNewBrowserTab?.() ??

onFocus () {
if (options.show) {
if (!options.browser.isHeadless) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options.show seems clearer to me?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options.show was coming from the run.ts defaultBrowserOptions which was removed in this PR. Here, we only have isHeadless, and I guess we have defaults.show here as well, which is also defined off of isHeadless. I figured it was clearer to use isHeadless again than to use defaults.show (which is actually just isHeadless)

Side note - the data flow and variable naming in this launcher is off the rails. It's due for a major refactor...

packages/server/lib/modes/interactive.ts Show resolved Hide resolved
@flotwig flotwig merged commit bcd7548 into develop Aug 31, 2022
@flotwig flotwig deleted the refactor-defaultBrowserOpts branch August 31, 2022 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants