7

I'm working on a browser extension (think SEOQuake) - I need to display some data about the search results that are shown.

Issue: If anything is added to the Google Instant results page while it's still in the process of being loaded, it'll overwrite any additions. I caught myself writing some really wonky setInterval business (waiting until the contents of ol#rso stop changing in size, stuff like that) so I suppose that means I'm not sure how to reliably determine if the page is done loading.

I could just have it wait 1-2 seconds but I really want to start fetching the data as soon as the results are loaded to save maximum amount of time.

Edit: Keep in mind, I can't use DOMElementWhatever because IE8 doesn't support it.

dsp_099
  • 5,801
  • 17
  • 72
  • 128
  • I'm not sure if there's a good cross-browser solution yet. There are the new [Mutation Observers](http://updates.html5rocks.com/2012/02/Detect-DOM-changes-with-Mutation-Observers) and even the [Mutation Summary](https://code.google.com/p/mutation-summary/) library to help, but no IE love. Another interesting approach using [CSS3 animation events](http://www.backalleycoder.com/2012/08/06/css-selector-listeners/), but no IE love :-p How about a `setInterval` hack for IE and Mutation Summary for everything else? – thirdender Apr 01 '13 at 03:19
  • You might be able to use the [onpropertychange](http://msdn.microsoft.com/en-us/library/ie/ms536956(v=vs.85).aspx) event for IE. – thirdender Apr 01 '13 at 03:28

1 Answers1

3

Try this:

window.addEventListener("message", function(e) {if(e.data == 'jrc') console.log('loaded')}, false);

That should work in IE 8+ and all other browsers: http://caniuse.com/#feat=x-doc-messaging

If that doesn't work in IE 8 (can't test in on my Mac right now), let me know. I believe I got some reasonably good understanding of the rs.js in the last hour. ;)

mrks
  • 8,033
  • 1
  • 33
  • 62
  • An edit that was rejected by reviewers because it should have been an answer suggested that, by now, it should say `e.data.type == 'sr'` – mrks Apr 15 '15 at 01:23