Skip to content

refactor: extract isWebviewIframe helper to reduce duplication in service worker#315498

Closed
harshagarwalnyu wants to merge 2 commits into
microsoft:mainfrom
harshagarwalnyu:fix/webview-sw-worker-resource-routing
Closed

refactor: extract isWebviewIframe helper to reduce duplication in service worker#315498
harshagarwalnyu wants to merge 2 commits into
microsoft:mainfrom
harshagarwalnyu:fix/webview-sw-worker-resource-routing

Conversation

@harshagarwalnyu
Copy link
Copy Markdown

This is a follow-up refactor complementing #315495.

What

Extracts the repeated webview iframe pathname check into a shared isWebviewIframe(url) helper:

js function isWebviewIframe(url) { return (url.pathname === ${rootPath}/ || url.pathname === ${rootPath}/index.html || url.pathname === ${rootPath}/index-no-csp.html); }

Both getOuterIframeClient and getWebviewIdForWorkerClient (added in #315495) performed identical inline pathname checks. This extracts them into one place.

Why

The Copilot AI reviewer on #315495 flagged this duplication as a drift risk — if entry points change, both sites would need updating independently. This addresses that concern.

Relationship to #315495

This PR is stacked on top of #315495 and should only be merged after it. Happy to squash these into a single commit if the maintainers prefer, or @yongsooim is welcome to pull this change directly.

Copilot AI review requested due to automatic review settings May 9, 2026 22:23
@harshagarwalnyu
Copy link
Copy Markdown
Author

Closing — the suggestion is already captured in the comment on #315495. @yongsooim can incorporate the change directly if useful.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the webview service worker client-resolution logic by extracting the repeated “is this a webview iframe entrypoint?” pathname check into a shared helper, reducing duplication in the worker/iframe matching flow.

Changes:

  • Extract repeated webview iframe pathname matching into isWebviewIframe(url).
  • Reuse isWebviewIframe in getOuterIframeClient and getWebviewIdForWorkerClient to keep entrypoint checks consistent.
  • Adjust resource/localhost request handling to resolve a missing webviewId for worker/sharedworker clients via getWebviewIdForWorkerClient.

Comment on lines 539 to +545
/**
* @param {string} webviewId
* @returns {Promise<Client[]>}
*/

/**
* @param {URL} url
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.

2 participants