Discussion:
[chromium-dev] Making a change so that chromium extension can force dom load to wait until content JS is done loading
Nicholas DiPiazza
2018-11-05 21:15:10 UTC
Permalink
In a chrome extension I'm making, I am having a race condition issue with
the content script and the dom page load.

I want to inject some javascript into the page to affect inline javascript
in the dom. Here is a detailed description of the
issue: https://stackoverflow.com/questions/53161083/how-to-share-a-unique-tab-id-between-content-and-background-scripts-without-an-a

But the problem is my content script has to query the background page. And
this requires async method call to *sendMessage.*

And because it's async, the dom inline javascript will load before prior to
the work being completed.

Is there some way I can get around this issue? I can build a custom version
of chromium if need be to make this happen.

I just need a way to tell the dom to "wait" until my pending async
*content.js* handlers have completed.
--
--
Chromium Developers mailing list: chromium-***@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+***@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/e220fd75-68e3-4e81-bcda-096ba1767d63%40chromium.org.
Nicholas DiPiazza
2018-11-05 23:44:53 UTC
Permalink
Hi Josh,

Thanks for the reply. I have tried making promises work and whenever I
introduce a promise into the content script it causes the dom to start
loading immediately after the main thread of the content script returns.

The only thing I have been able to do to get it to work is to add a
while(500 ms) hard loop into the main dom so that it doesn't load the rest
of the dom until the content async code has a chance to run.

What is a "global promise?" I can't find that defined anywhere on that
document you sent.

And how would onDocumentReady help? i'm not clear on that either.
Sounds like a use for a global 'promise' or 'onDocumentReady' (though I
recommend avoiding the weight of jQuery).
https://stackoverflow.com/questions/799981/document-ready-equivalent-without-jquery
https://developers.google.com/web/fundamentals/primers/promises
On Tue, Nov 6, 2018 at 8:15 AM Nicholas DiPiazza <
Post by Nicholas DiPiazza
In a chrome extension I'm making, I am having a race condition issue with
the content script and the dom page load.
I want to inject some javascript into the page to affect inline
https://stackoverflow.com/questions/53161083/how-to-share-a-unique-tab-id-between-content-and-background-scripts-without-an-a
But the problem is my content script has to query the background page.
And this requires async method call to *sendMessage.*
And because it's async, the dom inline javascript will load before prior
to the work being completed.
Is there some way I can get around this issue? I can build a custom
version of chromium if need be to make this happen.
I just need a way to tell the dom to "wait" until my pending async
*content.js* handlers have completed.
--
--
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups
"Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/e220fd75-68e3-4e81-bcda-096ba1767d63%40chromium.org
<https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/e220fd75-68e3-4e81-bcda-096ba1767d63%40chromium.org?utm_medium=email&utm_source=footer>
.
--
--
Chromium Developers mailing list: chromium-***@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+***@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAOsU1Oajt7giKvJPQoBRBR14Z8wS_pGSW3a1HyN7M97-5dnM9A%40mail.gmail.com.
Nicholas DiPiazza
2018-11-06 00:25:41 UTC
Permalink
Hi Josh,

Messaging is what my example in that link is using. When the Content script
makes the request to the Background script, it does so in an async manner.
And as soon as the main thread completes in the Content script (even though
the async request made to the background script has not yet completed), the
DOM load has already started.

I'm hoping there is a way to prevent that.
Actually sorry, those might help but it turns out there's a 'Google
approved' way to do something like this.
https://developer.chrome.com/extensions/messaging
This should help you call between your content script and background page.
Sorry about the mislead.
On Tue, Nov 6, 2018 at 10:45 AM Nicholas DiPiazza <
Post by Nicholas DiPiazza
Hi Josh,
Thanks for the reply. I have tried making promises work and whenever I
introduce a promise into the content script it causes the dom to start
loading immediately after the main thread of the content script returns.
The only thing I have been able to do to get it to work is to add a
while(500 ms) hard loop into the main dom so that it doesn't load the rest
of the dom until the content async code has a chance to run.
What is a "global promise?" I can't find that defined anywhere on that
document you sent.
And how would onDocumentReady help? i'm not clear on that either.
Sounds like a use for a global 'promise' or 'onDocumentReady' (though I
recommend avoiding the weight of jQuery).
https://stackoverflow.com/questions/799981/document-ready-equivalent-without-jquery
https://developers.google.com/web/fundamentals/primers/promises
On Tue, Nov 6, 2018 at 8:15 AM Nicholas DiPiazza <
Post by Nicholas DiPiazza
In a chrome extension I'm making, I am having a race condition issue
with the content script and the dom page load.
I want to inject some javascript into the page to affect inline
https://stackoverflow.com/questions/53161083/how-to-share-a-unique-tab-id-between-content-and-background-scripts-without-an-a
But the problem is my content script has to query the background page.
And this requires async method call to *sendMessage.*
And because it's async, the dom inline javascript will load before
prior to the work being completed.
Is there some way I can get around this issue? I can build a custom
version of chromium if need be to make this happen.
I just need a way to tell the dom to "wait" until my pending async
*content.js* handlers have completed.
--
--
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google
Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send
To view this discussion on the web visit
https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/e220fd75-68e3-4e81-bcda-096ba1767d63%40chromium.org
<https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/e220fd75-68e3-4e81-bcda-096ba1767d63%40chromium.org?utm_medium=email&utm_source=footer>
.
--
--
Chromium Developers mailing list: chromium-***@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+***@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAOsU1Ob%2Bd_Oqwjg%3Dyqog2y7DNPBZbTM7x6FSJ7ivdSHm7ct7Eg%40mail.gmail.com.
n***@gmail.com
2018-11-06 13:54:59 UTC
Permalink
Woxxom on stackoverflow helped me find the answer.



https://stackoverflow.com/a/53173322/1174024



Thanks!



From: Nicholas DiPiazza <***@gmail.com>
Sent: Monday, November 5, 2018 6:26 PM
To: Josh Pratt <***@google.com>; chromium-***@chromium.org
Subject: Re: [chromium-dev] Making a change so that chromium extension can force dom load to wait until content JS is done loading



Hi Josh,



Messaging is what my example in that link is using. When the Content script makes the request to the Background script, it does so in an async manner. And as soon as the main thread completes in the Content script (even though the async request made to the background script has not yet completed), the DOM load has already started.



I'm hoping there is a way to prevent that.



On Mon, Nov 5, 2018 at 5:59 PM Josh Pratt <***@google.com <mailto:***@google.com> > wrote:

Actually sorry, those might help but it turns out there's a 'Google approved' way to do something like this.

https://developer.chrome.com/extensions/messaging

This should help you call between your content script and background page.


Sorry about the mislead.



Josh Pratt | ChromeOS | ***@google.com <mailto:***@google.com>





On Tue, Nov 6, 2018 at 10:45 AM Nicholas DiPiazza <***@gmail.com <mailto:***@gmail.com> > wrote:

Hi Josh,



Thanks for the reply. I have tried making promises work and whenever I introduce a promise into the content script it causes the dom to start loading immediately after the main thread of the content script returns.



The only thing I have been able to do to get it to work is to add a while(500 ms) hard loop into the main dom so that it doesn't load the rest of the dom until the content async code has a chance to run.



What is a "global promise?" I can't find that defined anywhere on that document you sent.



And how would onDocumentReady help? i'm not clear on that either.



On Mon, Nov 5, 2018 at 4:39 PM Josh Pratt <***@google.com <mailto:***@google.com> > wrote:

Sounds like a use for a global 'promise' or 'onDocumentReady' (though I recommend avoiding the weight of jQuery).

https://stackoverflow.com/questions/799981/document-ready-equivalent-without-jquery
https://developers.google.com/web/fundamentals/primers/promises



Josh Pratt | ChromeOS | ***@google.com <mailto:***@google.com>





On Tue, Nov 6, 2018 at 8:15 AM Nicholas DiPiazza <***@gmail.com <mailto:***@gmail.com> > wrote:

In a chrome extension I'm making, I am having a race condition issue with the content script and the dom page load.



I want to inject some javascript into the page to affect inline javascript in the dom. Here is a detailed description of the issue: https://stackoverflow.com/questions/53161083/how-to-share-a-unique-tab-id-between-content-and-background-scripts-without-an-a



But the problem is my content script has to query the background page. And this requires async method call to sendMessage.



And because it's async, the dom inline javascript will load before prior to the work being completed.



Is there some way I can get around this issue? I can build a custom version of chromium if need be to make this happen.



I just need a way to tell the dom to "wait" until my pending async content.js handlers have completed.
--
--
Chromium Developers mailing list: chromium-***@chromium.org <mailto:chromium-***@chromium.org>
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+***@chromium.org <mailto:chromium-dev+***@chromium.org> .
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/e220fd75-68e3-4e81-bcda-096ba1767d63%40chromium.org <https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/e220fd75-68e3-4e81-bcda-096ba1767d63%40chromium.org?utm_medium=email&utm_source=footer> .
--
--
Chromium Developers mailing list: chromium-***@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+***@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/000401d475d8%244fb98110%24ef2c8330%24%40gmail.com.
Loading...