Synchronous pass messages

There is a known issue with Google Chrome yet not solved.
It is not possible to pass a synchronous message from background script to the content script on the page.
It makes impossible to handle the first page when the program is opened since the background script runs in parallel with the page rendering (content scripts).

Interesting request. Sync stuff is typically avoided. I think frame scripts have a sync message sender seen here: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsISyncMessageSender

I think best practice though is to avoid anything that is sync. You should make the other side wait. Or if you cant make the load wait, then load it invisible with opacity 0 pointer-events none something like that, then on response bring the content in with a nice transition opacity to 1 and other nice css stuff.

I guess you are talking about the Add-on SDK. Yes, the content scripts don’t have any means to do synchronous messaging. However, unlike with Chrome you can pass parameters to content scripts. So if your script needs some data to get going - that’s how you do it.

I talk about the new propose WebExtensions API.
There is a problem in Google Chrome and no good solution: https://stackoverflow.com/questions/26245397/comunicating-synchronously-with-a-chrome-extension
It is possible to workaround it but then it rises other implementation issues like: https://code.google.com/p/chromium/issues/detail?id=446453

In general there should be some configuration API that is going to ensure that content script has the relevant informatoin.

1 Like

Thanks for bringing it up, I’ll mention to the webext group maybe they can help you out.