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

#2902: Throw BusinessError on runBrick if tab is closed or has no access #2917

Merged
merged 6 commits into from
Mar 12, 2022

Conversation

fregante
Copy link
Contributor

@fregante fregante commented Mar 10, 2022

After the tab is closed, the timeout continues and then it throws a BusinessError.

Screen.Recording.mov

business-appropriate-business

@fregante fregante marked this pull request as ready for review March 10, 2022 09:49
@@ -87,7 +103,7 @@ export async function requestRunInBroadcast(
}

try {
const response = runBrick({ tabId: tab.id }, subRequest);
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 doesn't matter as much here, but I suppose wrapping the error still makes sense.


// The caught error isn't "The tab was closed" because of:
// https://github.com/pixiebrix/pixiebrix-extension/issues/2902#issuecomment-1062658248
throw new BusinessError("The tab was closed");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As the comment mentions, I think we can safely assume that this was the reason at this point.

The demo video included the previous error message.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can safely assume that this was the reason at this point

The other case is that PixieBrix doesn't have access to the other page (i.e., it's on a different domain that PixieBrix doesn't have access to). What's the error in that case?

Copy link
Contributor Author

@fregante fregante Mar 10, 2022

Choose a reason for hiding this comment

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

Yeah in that case we get the same error because the "receiving end did not respond". We can change this error to "PixieBrix doesn't have access to the tab or it was closed"

Separately I suppose we can find a solution to detect this lack of permissions, probably in the background before calling runBrick:

  • if target exists and we don't have access to it, throw error
  • else runBrick(target)

Copy link
Contributor

Choose a reason for hiding this comment

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

We can change this error to "PixieBrix doesn't have access to the tab or it was closed"

I'm good doing this for now in the PR

Separately I suppose we can find a solution to detect this lack of permissions, probably in the background before calling runBrick

👍

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 ended up implementing a better logic to tell the two errors apart:

  1. call canAccessTab (it will run true; on the tab)
  2. call runBrick + attach an "on tab closed" handler
  3. if the handler resolves first, the tab was closed

You can see that the "tab closed" error appears immediately, even if the messenger keeps retrying (we can stop the retries too, after sindresorhus/p-retry#53)

Screen.Recording.1.mov

And here you can see the specific error when PB doesn't have access:

Screen.Recording.2.mov

@fregante fregante changed the title #2902: Throw BusinessError when the target tab is closed #2902: Throw BusinessError on runBrick if tab is closed or has no access Mar 10, 2022
@@ -138,3 +138,13 @@ export async function setReduxStorage<T extends JsonValue = JsonValue>(
): Promise<void> {
await browser.storage.local.set({ [storageKey]: JSON.stringify(value) });
}

export async function onTabClose(watchedTabId: number): Promise<void> {
await new Promise<void>((resolve) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to unsubscribe the listener somehow after?

Copy link
Contributor

@twschiller twschiller left a comment

Choose a reason for hiding this comment

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

Thanks - left a commend on whether onCloseTab needs to somehow remove the listener after the tab is closed?

@twschiller twschiller added this to the 1.5.7 milestone Mar 10, 2022
@twschiller twschiller added the bug Something isn't working label Mar 10, 2022
@fregante fregante enabled auto-merge (squash) March 12, 2022 08:12
@fregante fregante merged commit 0fbfe24 into main Mar 12, 2022
@fregante fregante deleted the F/bug/closing-tab-business-error branch March 12, 2022 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

Incorrect "connection lost" message for multi-page flows
2 participants