Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Detect when a page is loaded (reliable, cross-browser)


  • Please log in to reply
16 replies to this topic
keyboardfreak
  • Members
  • 217 posts
  • Last active: Sep 27 2010 07:21 PM
  • Joined: 09 Oct 2004
I needed this feature and I've seen there was no solution which worked reliably in Firefox and Opera (I don't use IE, I assume there is some COM solution for it).

It uses user Javascript to monitor when the page is loaded and modifies the page title if it's loaded, so one can query it with wingetttitle.

For Firefox GreaseMonkey needs to be installed for the script to work, Opera has the necessary functionality built-in.

It's not a pure AutoHotkey solution, but at least it works reliably.

// ==UserScript==
// @name           loaded
// @namespace      my
// @description    indicate if a page is loded
// @include        http://www.cnn.com
// ==/UserScript==


window.addEventListener(
  'load',
  function (e) {
    document.title += " [loaded]";
 }, false);


See also this topic for an other feature using the same technique.

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: Oct 13 2016 01:04 AM
  • Joined: 21 Dec 2007

I needed this feature and I've seen there was no solution which worked reliably in Firefox and Opera (I don't use IE, I assume there is some COM solution for it)

Unfortunately there is no COM interface to the afore mentioned browsers thus no AHK COM solution to be had
Thank you keyboardfreak this has been many times asked for and is the best idea I have seen but it as you mentioned isnt an ahk solution but a Grease Monkey/Javascript Solution. Albeit a pretty darn good one
I think once Firefox exposes its internal methods and properties to other languages other than mozilla plug in based then the move from IE to mozilla in the corp world can finally begin. But not untill then
another interesting solution I found is
<!-- m -->http://www.autohotke... ... it firefox<!-- m -->

this is for Mozilla Firefox:

;-- from AUTOWQ german forum
;-- http://de.autohotkey.com/forum/topic29.html
#Persistent
UR=http://www.screamer-radio.com/
SC=Screamer      ;title
IE=%A_programfiles%\Mozilla Firefox\firefox.exe
CL=ahk_class MozillaWindowClass

Run,%IE% %UR%,,max
WinWait,%SC%
IfWinNotActive,%SC%,,WinActivate,%SC%
WinWaitActive,%SC%
Sleep,300
SetTimer,FireFoxLoadDetect,500
Return

FireFoxLoadDetect:    ;check firefox rotary wheel
col32:=0xB2B2B2
col16:=0xB5B2B5
WinGetPos,,,WI,HI,A
;---Firefox 1.5 / 2.0 ------
Wi -= 16                            ; Position from wheel = Windowswidth -16
PixelGetColor, OutputVar, Wi, 41    ; 41 = Position from top

if outputvar in %col16%,%col32%
  {
  msgbox,%UR% is open
  ExitApp
  }
return


As far as COM IE and Gui Browsers go
<!-- m -->http://www.autohotke... ... highlight=<!-- m -->
The above link is a complete COM IE Gui Browser tutorial
This is just an excerpt the first 2 snippets do not standalone but the 3rd one that I got from Sean does

wait for it to finish loading

loop 
      If (rdy:=COM_Invoke(pwb,"readyState") = 4)
         break
another way to check if a page has loaded using javascript via com
pwin:=COM_Invoke(doc:=COM_Invoke(pwb,"Document"),"parentWindow")	
	if pwin is integer
      loop 
         If rdy:=COM_Invoke(pwin, "execScript","var rdy=document.readyState","rdy") = "complete"  
            break
of course always release objects not textyou wouldnt release rdy but you would release doc in the example above
a comletely independent way to check readystate requires tab if enabled to be the selected tab but doesnt require the window to be active
<!-- m -->http://www.autohotke... ... sc&start=0<!-- m -->

It'll check whether a webpage is completely loaded or not in the active Internet Explorer.

NEED the latest COM Standard Library.

; Run, iexplore.exe http://www.google.com/
MsgBox, % IEReady()
Return

IEReady(hIESvr = 0)
{
	If Not	hIESvr
	{
		Loop,	50
		{
			ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, A ; ahk_class IEFrame
			If	hIESvr
				Break
			Else	Sleep 100
		}
		If Not	hIESvr
			Return	"""Internet Explorer_Server"" Not Found."
	}
	Else
	{
		WinGetClass, sClass, ahk_id %hIESvr%
		If Not	sClass == "Internet Explorer_Server"
			Return	"The specified control is not ""Internet Explorer_Server""."
	}

	COM_Init()
	If	DllCall("SendMessageTimeout", "Uint", hIESvr, "Uint", DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT"), "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 1000, "UintP", lResult)
	&&	DllCall("oleacc\ObjectFromLresult", "Uint", lResult, "Uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0, "UintP", pdoc)=0
	&&	pdoc && pweb:=COM_QueryService(pdoc,IID_IWebBrowserApp:="{0002DF05-0000-0000-C000-000000000046}")
		Loop
			If	COM_Invoke(pweb, "ReadyState") = 4
				Break
			Else	Sleep 500
	COM_Release(pdoc)
	COM_Release(pweb)
	COM_Term()
	Return	pweb ? "DONE!" : False
}


Never lose.
WIN or LEARN.

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
Simple yet effective, another why didn't I think of that :p If there are any GM clones for IE window.attachEvent('onload',function (){document.title+=' [loaded]';}); would be a valid hook.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


Krogdor
  • Members
  • 1391 posts
  • Last active: Jun 08 2011 05:31 AM
  • Joined: 18 Apr 2008
Oooh, I like it :D

Thanks for posting this.

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: Oct 13 2016 01:04 AM
  • Joined: 21 Dec 2007
i tried injecting this into IE and it failed to update the title ?? even tried updating title with
javascript:void(document.title="[loaded]")
nothing :cry:
Never lose.
WIN or LEARN.

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012

i tried injecting this into IE and it failed to update the title

Not sure why, perhaps it's an anti-XSS rule. Firefox doesn't have this problem. Here's an example of the embedded script, which works.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: Oct 13 2016 01:04 AM
  • Joined: 21 Dec 2007

i tried injecting this into IE and it failed to update the title

Not sure why, perhaps it's an anti-XSS rule. Firefox doesn't have this problem. Here's an example of the embedded script, which works.

oh i know thats why i think its odd
its valid javascript it should work
its very odd indeed
Im gonna do some research of my own see if i can root it out for sure
Never lose.
WIN or LEARN.

yogi
  • Members
  • 15 posts
  • Last active: Dec 22 2011 03:33 PM
  • Joined: 02 Sep 2007

It's not a pure AutoHotkey solution, but at least it works reliably.

// ==UserScript==
// @name           loaded
// @namespace      my
// @description    indicate if a page is loded
// @include        http://www.cnn.com
// ==/UserScript==


window.addEventListener(
  'load',
  function (e) {
    document.title += " [loaded]";
 }, false);

I was so excited to stumble across this thread, I tried it, but it doesnt work in Opera 10.10
I dont know how to correct or update the js. Please help :)
no fate but what we make

jsBumbler
  • Guests
  • Last active:
  • Joined: --

I was so excited to stumble across this thread, I tried it, but it doesnt work in Opera 10.10
I dont know how to correct or update the js. Please help :)


It should work (it works on v9.6x), but you need to modify the js for the sites you want it to work on (you might find some help on the Opera site). Make sure that you have user js enabled in Opera configuration.

If you modify the original post js code to look like this
// ==UserScript== 
// @name           loaded 
// @namespace      my 
// @description    indicate if a page is loded 
// ==/UserScript== 


window.addEventListener( 
  'load', 
  function (e) { 
    document.title += " [loaded]"; 
 }, false);
it should work on all sites (as originally posted in only works on http://www.cnn.com).

yogi
  • Members
  • 15 posts
  • Last active: Dec 22 2011 03:33 PM
  • Joined: 02 Sep 2007
works like a charm now, thanks so much for the corrected javascript!!! :))
no fate but what we make

sam.reckoner
  • Members
  • 51 posts
  • Last active: Apr 06 2012 02:20 AM
  • Joined: 11 Oct 2007
I'm very excited about this thread, but I don't know enough about JavaScript or greasemonkey in Firefox to be able to apply the techniques here.

How about some step-by-step instructions to get this to work in Firefox?

Thanks in advance.

rifts
  • Guests
  • Last active:
  • Joined: --
this only works with sites that have swf on the page

like google doesnt work, youtube does
facebook doesnt work, yahoo does

DTiziano
  • Guests
  • Last active:
  • Joined: --

this only works with sites that have swf on the page

like google doesnt work, youtube does
facebook doesnt work, yahoo does


I am using Opera and it works perfectly also with google and yahoo.
I do not have a facebook account so I did not tested.
The only modification I made is:
"document.title = "loaded-" + document.title; "

to display it at the beginning of the title,
because on sites with very long title the "load" is not displayed.

Very nice job keyboardfreak, simple and powerful

mauritius
  • Members
  • 75 posts
  • Last active: Aug 22 2015 09:53 AM
  • Joined: 04 Aug 2010
1. is this possible to modify the page title when it's loading and then change it again when page is completely loaded?
2. what about situation when we don't know exacly address of page? at opera page i've found:

// ==UserScript==
// @include <!-- m -->http://example.com/*<!-- m -->
// @include <!-- m -->http://www.example.com/*<!-- m -->
// @exclude <!-- m -->http://example.com/directory/*<!-- m -->
// @exclude <!-- m -->http://www.example.com/example.html<!-- m -->
// ==/UserScript==

but it doesn't work when there is a subdomain e.g: <!-- m -->http://subdomain.exa...tg.cgi?23424234<!-- m -->
how can we change jsBumbler's script to work in this situation?

thanks in advance

Jamie
  • Members
  • 129 posts
  • Last active: Dec 02 2012 04:59 AM
  • Joined: 26 Mar 2010
This has been mentioned in other threads before, but MozRepl lets you connect over a socket and do pretty much anything with Firefox. In this way it can be very scriptable. You can do essentially anything a plugin can do, not just js within the page. For a while I was sending it commands from AHK and it worked great.