Skip to content

[flutter_local_notifications_web] focus the tab on notification click + wait for SW activation + cache burst for SW file changes - #2820

Open
coder-with-a-bushido wants to merge 4 commits into
MaikuB:masterfrom
famedly:karthi/web-tab-focus
Open

coder-with-a-bushido wants to merge 4 commits into
MaikuB:masterfrom
famedly:karthi/web-tab-focus

Conversation

@coder-with-a-bushido

@coder-with-a-bushido coder-with-a-bushido commented Sep 1, 2026 •

Copy link
Copy Markdown
  1. Right now when using the plugin, the notification click doesn't focus the tab on web when the tab is open. This PR fixes that since that's the naturally expected behaviour.
  2. initialize registered the service worker and immediately subscribed to messages. If the worker was still installing, notification clicks could be missed. Now, initialize waits until the worker is activated (10s timeout) before listening for clicks.
  3. Browsers could also keep serving an old notifications_service_worker.js, so SW updates did not always take effect. So, I fixed it by adding ?v=1.0.0 to SW URL so a version bump forces browsers to fetch the new file instead of the cached one.

@coder-with-a-bushido

coder-with-a-bushido commented Sep 3, 2026 •

Copy link
Copy Markdown
Author

Hi @MaikuB, it would be nice to get this PR reviewed. It has minimal changes but I think these high impact for users. I am ready to do the changes requested to get this merged.

Thank you in advance :)

@coder-with-a-bushido coder-with-a-bushido changed the title [flutter_local_notifications_web] focus the tab on notification click [flutter_local_notifications_web] focus the tab on notification click + wait for SW activation + cache burst for SW file changes Sep 3, 2026
@MaikuB
MaikuB requested a lite review from Copilot September 13, 2026 06:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Address the two moderate service-worker reliability issues before approval.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Updates web notification handling to focus existing tabs, wait for service-worker activation, and bust cached worker scripts.

Changes:

  • Focuses an open tab when a notification is clicked.
  • Waits up to 10 seconds for service-worker activation.
  • Adds a version query parameter to the worker URL.
File summaries
File Summary Findings
flutter_local_notifications_web/web/notifications_service_worker.js Focuses the notification client before sending the message. Await client.focus() and include the full operation in event.waitUntil() (moderate, 3 votes).
flutter_local_notifications_web/lib/src/plugin.dart Adds activation waiting and cache busting. Register the message listener before waiting for activation (moderate, 2 votes). Correct “burst cache” to “cache bust” (nit, 1 vote).
Review details

Suppressed comments (1)

flutter_local_notifications_web/lib/src/plugin.dart:157

  • The standard term is “cache bust”; “burst cache” is a typo in this newly added comment.
      // Add version query parameter to the service worker file to burst cache
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread flutter_local_notifications_web/lib/src/plugin.dart Outdated
Comment thread flutter_local_notifications_web/web/notifications_service_worker.js Outdated
completeIfActivated();
}).toJS;
completeIfActivated();
return completer.future.timeout(const Duration(seconds: 10));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

What's the reason for 10 seconds? Looks like a magic number

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

sorry for the super late reply, yes it's arbitrary but I set it so even devices with poor internet connection can run without throwing.

For reference, flutter service worker sets 4 seconds for a similar case:
https://github.com/flutter/flutter/blob/9911f49fc707c782835c41bd7945cdf23ede2598/engine/src/flutter/lib/web_ui/flutter_js/src/service_worker_loader.js#L85

I'm open for suggestions as well.

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