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

fix: Fix exiting fullscreen on Safari #5439

Merged
merged 2 commits into from
Jul 26, 2023

Conversation

theodab
Copy link
Contributor

@theodab theodab commented Jul 25, 2023

screen.orientation.unlock is not defined on Safari, even though screen.orientation is.
This changes our orientation polyfill to add that method to screen.orientation.

Fixes #5437

screen.orientation.unlock is not defined on Safari, even though
screen.orientation is. This change checks for the presence of
that function before calling it.

Fixes shaka-project#5437
@theodab theodab added the type: bug Something isn't working correctly label Jul 25, 2023
@theodab theodab changed the title fix: Fix screen unlocking on Safari fix: Fix exiting fullscreen on Safari Jul 25, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jul 25, 2023

Incremental code coverage: 31.25%

@WINOFFRG
Copy link
Contributor

Hey @theodab With this should we even extend and patch the existing Orientation Polyfill with reference from https://github.com/chmanie/o9n#supported-browsers?

@theodab
Copy link
Contributor Author

theodab commented Jul 26, 2023

Hey @theodab With this should we even extend and patch the existing Orientation Polyfill with reference from https://github.com/chmanie/o9n#supported-browsers?

I guess updating the polyfill would be nicer, you're right. It looks like that polyfill just falls through to a no-op for Safari, so I'm not sure if it will be very relevant here as a reference though.

@WINOFFRG
Copy link
Contributor

Yes it's a noop for Safari, Reason for patching the polyfill as on custom apps the developers even noticing that an Orientation Polyfill exists but still it fails to handle it on Safari.

Copy link
Member

@joeyparrish joeyparrish left a comment

Choose a reason for hiding this comment

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

It's not clear to me how this fixes exiting fullscreen. If we're already called orientation.lock(), how is okay to skip unlock()?

static installBasedOnScreenMethods_() {
if (screen.orientation.lock === undefined) {
screen.orientation.lock = (orientation) => {
shaka.log.info('screen.orientation.lock is a no-op');
Copy link
Member

Choose a reason for hiding this comment

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

What happens when this no-op is used? How does the app behavior differ from the normal case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, this no-op doesn't change anything because we already wrap the lock method in a try-catch to silence errors. I just included it for sake of completeness.

}
if (screen.orientation.unlock === undefined) {
screen.orientation.unlock = () => {
shaka.log.info('screen.orientation.unlock is a no-op');
Copy link
Member

Choose a reason for hiding this comment

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

Same question here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one improves things because, on desktop Safari, neither lock nor unlock are implemented. So we don't need to unlock the screen, because we never locked it in the first place; we just need to prevent the method call from erroring, so that we can move on to the part of the code that calls document.exitFullscreen.
I guess technically this approach, where each methods is filled with a no-op independently, would lead to a weird result if the browser has lock implemented but doesn't have unlock implemented. But I would hope that no browser provides an API for locking the screen without providing an API for unlocking it, that sounds like an accident waiting to happen.

Copy link
Member

Choose a reason for hiding this comment

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

I had the impression from this PR and the comments on it that only unlock() was missing on Safari. Thanks for clarifying.

@joeyparrish joeyparrish merged commit ed93a0c into shaka-project:main Jul 26, 2023
@theodab theodab deleted the screenOrientBranch branch July 28, 2023 09:56
joeyparrish pushed a commit that referenced this pull request Aug 19, 2023
`screen.orientation.unlock` is not defined on Safari, even though `screen.orientation` is.
This changes our orientation polyfill to add that method to `screen.orientation`.

Fixes #5437
joeyparrish pushed a commit that referenced this pull request Aug 20, 2023
`screen.orientation.unlock` is not defined on Safari, even though `screen.orientation` is.
This changes our orientation polyfill to add that method to `screen.orientation`.

Fixes #5437
@shaka-bot shaka-bot added the status: archived Archived and locked; will not be updated label Sep 24, 2023
@shaka-project shaka-project locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated type: bug Something isn't working correctly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: screen.orientation.unlock() is not a function
4 participants