-
Notifications
You must be signed in to change notification settings - Fork 916
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
[Obsolete] Fix messaging in chrome extension pages (#2846) #2863
base: main
Are you sure you want to change the base?
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Enkot, you were correct that the current SDK isn't working for Chrome Extension.
Thanks for making the fix and tests w/ it 👍
@@ -218,6 +218,30 @@ describe('SwController', () => { | |||
expect(postMessageSpy).to.have.been.calledOnceWith(expectedMessage); | |||
}); | |||
|
|||
it('sends a message to chrome extension clients if a chrome extension client is visible', async () => { | |||
const client: Writable<WindowClient> = (await self.clients.openWindow( | |||
'chrome-extension://aihpiglmnhnhijdnjghpfnlledckkhja/popup.html' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like a real extension id. can we have it to be more generic? something like "chrome-extension://testExtensionId/popup.html" or whatever.
@@ -297,7 +297,7 @@ function hasVisibleClients(clientList: WindowClient[]): boolean { | |||
client.visibilityState === 'visible' && | |||
// Ignore chrome-extension clients as that matches the background pages | |||
// of extensions, which are always considered visible for some reason. | |||
!client.url.startsWith('chrome-extension://') | |||
!(client.url.startsWith('chrome-extension://') && client.url.endsWith("_generated_background_page.html")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this will work for auto-gen background.html. The next step is probably to have a more generic solution that would work for all situation (user defined background html) and across browser if applicable 😎
@@ -241,6 +265,32 @@ describe('SwController', () => { | |||
}); | |||
}); | |||
|
|||
it('does not send a message to chrome extension background pages if background page is visible', async () => { | |||
const client: Writable<WindowClient> = (await self.clients.openWindow( | |||
'chrome-extension://aihpiglmnhnhijdnjghpfnlledckkhja/_generated_background_page.html' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
Hi @zwu52, can you please review last changes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enkot,
apologies for the delay. LGTM. Made some minor nits.
* @returns If client is the background page of browser extension, this method will | ||
* resolve to true, otherwise false. | ||
*/ | ||
async function isBackgroundClient(client: WindowClient): Promise<boolean> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: how about isBackgroundExtension
or isExtensionBackgroundClient
. Just to make clear we're talking in the extension context
try { | ||
const backgroundClient = await runtime.getBackgroundClient(); | ||
return client === backgroundClient; | ||
} catch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enkot,
Can we have a debug log here on the error and error message so it would be easier for folks to debug if they hit this path and wanted to get information?
Hi @zwu52, |
Enkot, |
Hi @zwu52, Do we have any chance to merge this PR? |
Hi Enkot, apologies that I didn't realize the PR wasn't checked in. Thanks for pinging. This PR had some conflicts so I made this based on your PR. Feel free to use it to update your PR and I'll merge your PR. |
Fixed problem with not working
onMessage
handler in chrome extension pages.