Get the URL of the current (active) browser tab

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
atnbueno
Posts: 89
Joined: 12 Oct 2013, 04:45
Contact:

Re: Get the URL of the current (active) browser tab

14 Apr 2016, 15:16

Hello again.

Kudos, could you please check this version of the script with your Edge browser?
https://dl.dropboxusercontent.com/u/741 ... _kudos.ahk

For now it's just an ugly workaround but I'd like to know if I'm in the right path to nail the problem with ApplicationFrameWindow.


Regards,
Antonio

[EDIT 2016-04-15]I think I found the problem. I've updated the script above with the tentative solution (no ugly workaround needed! :)).[/EDIT]
Last edited by atnbueno on 15 Apr 2016, 14:39, edited 2 times in total.
User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: Get the URL of the current (active) browser tab

15 Apr 2016, 02:15

Hi atnbueno,
it works with firefox nightly multiprocess :-)
but Edge produces an error for loading a type bib/dll

Code: Select all

---------------------------
GetActiveBrowserURL_kudos.ahk
---------------------------
Error:  0x80029C4A - Fehler beim Laden der Typbibliothek/DLL.

Source:		(null)
Description:	(null)
HelpFile:		(null)
HelpContext:	0

Specifically: accChildCount

	Line#
	119: Return,ComObj(9, ComObjQuery(Acc,"{618736e0-3c3d-11cf-810c-00aa00389b71}"), 1)
	120: }
	121: {
	122: if ComObjType(Acc,"Name") != "IAccessible"  
	123: ErrorLevel := "Invalid IAccessible Object"
	124: Else
	124: {
--->	125: Acc_Init(), cChildren:=Acc.accChildCount, Children:=[]  
	126: if DllCall("oleacc\AccessibleChildren", "Ptr",ComObjValue(Acc), "Int",0, "Int",cChildren, "Ptr",VarSetCapacity(varChildren,cChildren*(8+2*A_PtrSize),0)*0+&varChildren, "Int*",cChildren)=0  
	126: {
	127: Loop,%cChildren%
	128: i:=(A_Index-1)*(A_PtrSize*2+8)+8, child:=NumGet(varChildren,i), Children.Insert(NumGet(varChildren,i-8)=9?Acc_Query(child):child), NumGet(varChildren,i-8)=9?ObjRelease(child):  
	129: Return,Children.MaxIndex()?Children:
	130: }
	130: Else

Continue running the script?
---------------------------
Ja   Nein   
---------------------------
User avatar
atnbueno
Posts: 89
Joined: 12 Oct 2013, 04:45
Contact:

Re: Get the URL of the current (active) browser tab

15 Apr 2016, 14:36

I'm glad it works with Firefox Nightly, haichen :)

About the error, I don't know what to tell you :eh: The only DDL used for non-legacy browsers (like both Firefox Nightly and MS Edge) is oleacc.dll :think:


Regards,
Antonio

P.S. Test script updated above
User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: Get the URL of the current (active) browser tab

16 Apr 2016, 12:41

Now I had time to test it on my netbook and it worked with edge. Gratulation!! and thank you. So my desktop pc may have a problem..
goosey
Posts: 2
Joined: 11 May 2016, 08:39

Re: Get the URL of the current (active) browser tab

11 May 2016, 08:59

Is there any way to get this to work with Vivaldi browser (based on Chrome)? I've tried a few work arounds using control l+ control c but it's very unreliable.
User avatar
atnbueno
Posts: 89
Joined: 12 Oct 2013, 04:45
Contact:

Re: Get the URL of the current (active) browser tab

11 May 2016, 15:55

goosey, unfortunately no :-(

Vivaldi does not support neither DDE nor MSAA (the two methods my script uses to get information from the browsers).

As soon as version 1.1 came out I re-tried, again without success :-(
goosey
Posts: 2
Joined: 11 May 2016, 08:39

Re: Get the URL of the current (active) browser tab

12 May 2016, 09:09

Ok, thank you for answering. Time to refine copy and paste timing then, setting show full url helped by the way, for anyone else reading.
technotron
Posts: 4
Joined: 21 Sep 2014, 07:43

Re: Get the URL of the current (active) browser tab

15 May 2016, 01:52

I got this script working just fine with both Firefox and Chrome. However, the url cannot be determined with the Pale Moon browser. Are you willing to add support for it? It was originally derived from older versions of Firefox's code and branched from it.

site:
https://www.palemoon.org/

>>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
Pale Moon - Congratulations - Pale Moon
ahk_class MozillaWindowClass
User avatar
atnbueno
Posts: 89
Joined: 12 Oct 2013, 04:45
Contact:

Re: Get the URL of the current (active) browser tab

15 May 2016, 07:10

technotron, if ahk_class is "MozillaWindowClass", the tweak I mentioned a couple of months ago should work with Pale Moon (both x86 and x64 versions). If there's any problem, I'll gladly look into it :)

I've updated the original code with this change, as well as with the fix for occasional Edge problems :roll:


Regards,
Antonio

P.S. I've asked in the Vivaldi forums about automation/accessibility support and they say they're working on it :thumbup:
User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: Get the URL of the current (active) browser tab

15 May 2016, 10:57

Found this Accessibility Viewer
https://www.paciellogroup.com/resources/aviewer/
May be this could be interesting for you (or others).
technotron
Posts: 4
Joined: 21 Sep 2014, 07:43

Re: Get the URL of the current (active) browser tab

15 May 2016, 13:10

atnbueno wrote:technotron, if ahk_class is "MozillaWindowClass", the tweak I mentioned a couple of months ago should work with Pale Moon (both x86 and x64 versions). If there's any problem, I'll gladly look into it :)

I've updated the original code with this change, as well as with the fix for occasional Edge problems :roll:


Regards,
Antonio

P.S. I've asked in the Vivaldi forums about automation/accessibility support and they say they're working on it :thumbup:
I tried out the new script on both Pale Moon 32 bit and 64 bit. Unfortunately it still cannot determine the url. It still works on Firefox and Chrome though.

By the way, on line 66 are the quotes supposed to be unclosed?

Code: Select all

	StringSplit, sWindowInfo, csvWindowInfo, `"
User avatar
atnbueno
Posts: 89
Joined: 12 Oct 2013, 04:45
Contact:

Re: Get the URL of the current (active) browser tab

15 May 2016, 17:43

Hello again.

technotron, you're right. I've tried both x86 and x64 versions of Pale Moon and I can't reach the address bar (my script needs a "path" from the window to the address bar than can be detected with ACC). It's the same problem I have with the Vivaldi browser: The address bar is there, but I can't find it with the accessibility API :(

Specifically, if I can't "select" the address bar with jethrow's AccViewer.ahk, I can't read it :think: I'm mentioning this because I'm stumped with this case. Right now I have no clue on how to solve it. Ideas, anyone?

And haichen, thanks for the link. I use another viewer but the one you link provides additional information :thumbsup:


Regards,
Antonio

P.S. I forgot: Yes, that single double quote is correct (it's the character to use as delimiter for the string splitting)
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
Contact:

Re: Get the URL of the current (active) browser tab

16 May 2016, 11:11

Hi,
atnbueno wrote:I've tried both x86 and x64 versions of Pale Moon and I can't reach the address bar (my script needs a "path" from the window to the address bar than can be detected with ACC).
Pale Moon say they disabled accessibility features explicitly: https://www.palemoon.org/technical.shtml#features
It's the same problem I have with the Vivaldi browser: The address bar is there, but I can't find it with the accessibility API :(
There's a kind-of workaround for Vivaldi (actually works in Chrome too to play with the rendered web page): turn on global accessibility mode in chrome://accessibility. I say workaround because:
  • While the address bar does get exposed (95% sure of this - sometimes I found it with Microsoft's Inspect [Object]), so do the rest of the elements on the page...
    • Leaving the mode on does slow things down a bit when browsing...
    • And, of course, users must enable the mode first
  • The global accessibility mode does not seem to persist when the browser is restarted
Best regards
User avatar
atnbueno
Posts: 89
Joined: 12 Oct 2013, 04:45
Contact:

Re: Get the URL of the current (active) browser tab

16 May 2016, 12:34

Thanks, qwerty12. Really useful information.

The Pale Moon link is clear: They don't care for automation/accessibility, so I guess I won't care about Pale Moon :mrgreen:

I did not gave up inmediately. I also tried using DDE (the older inter-process messaging technology I use with legacy browsers) but it didn't work either :(

The information about Vivaldi is a bit more hopeful. The address bar can be reached in this mode, although it requires some very specific steps to get the full URL (unless "Show full URL" is also enabled by the user in the address bar options). The lack of persistence is annoying, but at least the functionality is there :thumbup: Let's hope they decide to enable accessibility at least for the UI.


Regards,
Antonio
Kudos
Posts: 7
Joined: 23 Aug 2015, 05:52

Re: Get the URL of the current (active) browser tab

16 May 2016, 17:35

Hi Antonio,

I'm really sorry for not replying for so long. I was unaware of all the replies here.

I have just tried the latest code and I still consistently have the same issue in MS Edge 'The URL couldn't be determined'. Do you have any suggestions of what I can do to help troubleshoot this?

I would gladly try any ugly workaround if you can share that again.

Thanks!!
Kudos
User avatar
atnbueno
Posts: 89
Joined: 12 Oct 2013, 04:45
Contact:

Re: Get the URL of the current (active) browser tab

18 May 2016, 15:16

Hello Kudos,

Don't worry. We all have our downtimes :-)

If the current code still fails, I still have no idea of what's happening to you. I've been using Edge with the published code for days without a single problem.

But hey, let's keep trying. I've gone back to the "ugly workaround" in this version:
https://dl.dropboxusercontent.com/u/741 ... _kudos.ahk

Please try it and let's see if anything changes on your side.

Regards,
Antonio

P.S. I've also found a not-very-ugly workaround for Vivaldi that seems to work 100% :-)
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
Contact:

Re: Get the URL of the current (active) browser tab

18 May 2016, 15:51

atnbueno wrote: I've also found a not-very-ugly workaround for Vivaldi that seems to work 100% :-)
Nice work! :thumbup:
Kudos
Posts: 7
Joined: 23 Aug 2015, 05:52

Re: Get the URL of the current (active) browser tab

18 May 2016, 16:48

Hi Antonio!

It turns out I've been really stupid! :crazy: My dev machine has not installed updates for ages so I was running an old version of Edge - 20.10240. Tried your latest code and the workaround on another PC of mine with (more recent) Edge 25 and both work perfectly. :clap:

So I think my issue was just that I need to install updates! :facepalm:

Thanks for all your help!

Kudos
technotron
Posts: 4
Joined: 21 Sep 2014, 07:43

Re: Get the URL of the current (active) browser tab

19 May 2016, 06:11

qwerty12 wrote: Pale Moon say they disabled accessibility features explicitly: https://www.palemoon.org/technical.shtml#features
That's really too bad. I tried to approach this different way. I used a greasemonkey script since it has a function that can set the clipboard and can interact the browser directly. Here's the code snippet if anyone is interested. It's not autohotkey though:

Code: Select all

==UserScript==
// @name        custom grim's copy_page_url
// @namespace   namesp
// @description copies page url with ctrl + shift + c
// @include     *
// @version     1
// @grant    GM_setClipboard
// ==/UserScript==

// http://stackoverflow.com/questions/13075645/how-to-copy-data-to-the-clipboard-with-greasemonkey

var pageUrl = window.location.href
var textToCopy = pageUrl;


// start copy text to clipboard
(function(){
document.addEventListener('keydown', function(e) {
  // pressed ctrl+shift+c
  if (e.keyCode == 67 && e.shiftKey && e.ctrlKey && !e.altKey && !e.metaKey) {
   GM_setClipboard(textToCopy);
  }
}, false);
})();
User avatar
atnbueno
Posts: 89
Joined: 12 Oct 2013, 04:45
Contact:

Re: Get the URL of the current (active) browser tab

19 May 2016, 15:50

Kudos, ouch :roll:

technotron, I'm a big fan of GreaseMonkey/TamperMonkey myself :thumbup: A quite common trick to expose the URL of each tab is to add it to the page title when it loads, so AutoHotkey can easily get it. The GM script for this couldn't be simpler and you wouldn't need to use the clipboard or listen to the keyboard inside every tab :)

I've just updated the code and added the Vivaldi workaround in the original post, in case anyone is interested.


Regards,
Antonio

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: gwarble and 18 guests