Get browser URL
-
- Addict
- Posts: 1309
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
Get browser URL
I am writing an application where the users need to download images (jpg only) from a displayed web page.
I have had some success with downloading images from a web address but would like the user to either use the webgadget to navigate to a web page or use FireFox to find the image. So I need to use the web gadget as a browser or grab the current web address from Firefox is any of this possible or do I give up now?
regards
collectordave
__________________________________________________
Thread title changed
"Is it possible?">"Get browser URL"
19.11.2018
RSBasic
I have had some success with downloading images from a web address but would like the user to either use the webgadget to navigate to a web page or use FireFox to find the image. So I need to use the web gadget as a browser or grab the current web address from Firefox is any of this possible or do I give up now?
regards
collectordave
__________________________________________________
Thread title changed
"Is it possible?">"Get browser URL"
19.11.2018
RSBasic
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
- RSBasic
- Moderator
- Posts: 1218
- Joined: Thu Dec 31, 2009 11:05 pm
- Location: Gernsbach (Germany)
- Contact:
Re: Get browser URL
Hello collectordave
I changed the title of your thread.
Please do not write thread titles like "Is it possible?", because the title is not meaningful and is bad for the search. Thank you
I changed the title of your thread.
Please do not write thread titles like "Is it possible?", because the title is not meaningful and is bad for the search. Thank you
Re: Get browser URL
See this post: viewtopic.php?p=378044#p378044collectordave wrote:grab the current web address from Firefox
But it doesn't work with the latest Firefox anymore.
Re: Get browser URL
Why? There's no sensible reason I could think of to read the current browser adress without the user needing to give you said address, if you want to write a content grabber, except for a spy-tool.
If you don't want the user to copy and paste the address bar for convenience sake, you need to write a browser plugin/addon.
If you don't want the user to copy and paste the address bar for convenience sake, you need to write a browser plugin/addon.
Re: Get browser URL
Hi
Tested with latest FF
URL copied to ClipBoard and listed to ListView()
Tested with latest FF
URL copied to ClipBoard and listed to ListView()
Code: Select all
#CHILDID_SELF = 0
#WINEVENT_OUTOFCONTEXT = 0
#WINEVENT_SKIPOWNPROCESS = $2
#EVENT_OBJECT_FOCUS = $8005
#EVENT_OBJECT_VALUECHANGE = $800E
#ROLE_SYSTEM_DOCUMENT = $F
#ROLE_SYSTEM_PANE = $10
#ROLE_SYSTEM_TEXT = $2A
Procedure WinEventFunc(HookHandle.l, hEvent.l, hwnd.l, idObject.l, idChild.l, idEventThread.l, dwmsEventTime.l)
Protected *objectIa.IAccessible, a.i=0, b.i=0, c.i=0, d.i=0, e.i=0, f.i=0, g.i=0, h.i=0, i.i=0, j.i=0
Static previousUrl$
Select hEvent
Case #EVENT_OBJECT_FOCUS, #EVENT_OBJECT_VALUECHANGE
className$ = Space(#MAX_PATH)
GetClassName_(hwnd, @className$, #MAX_PATH)
If className$ = "MozillaWindowClass" Or className$ = "Internet Explorer_Server" Or className$ = "IEFrame" Or className$ = "OperaWindowClass"
If CallFunction(0, "AccessibleObjectFromEvent", hwnd, idObject, idChild, @*objectIa, @v.VARIANT) = #S_OK
v.VARIANT\vt = #VT_I4
v\lVal = #CHILDID_SELF
If *objectIa\get_accRole(v, @v) = #S_OK
If v\lVal = #ROLE_SYSTEM_PANE Or v\lVal = #ROLE_SYSTEM_DOCUMENT Or v\lVal = #ROLE_SYSTEM_TEXT
v\vt = #VT_I4
v\lVal = #CHILDID_SELF
url$ = Space(#MAX_PATH)
bstr = @url$
If *objectIa\get_accValue(v, @bstr) = #S_OK
url$ = PeekS(bstr, -1, #PB_Unicode)
If previousUrl$ <> url$ And url$ <> ""
AddGadgetItem(0, -1, url$)
SetClipboardText(url$)
previousUrl$ = url$
EndIf
EndIf
EndIf
*objectIa\Release()
EndIf
EndIf
EndIf
EndSelect
EndProcedure
OpenWindow(0, 550, 450, 500, 500, "Get Browser URL", #PB_Window_MinimizeGadget)
ListViewGadget(0, 10, 10, 480, 480)
CoInitialize_(0)
hdll = OpenLibrary(0, "Oleacc.dll")
eHook = SetWinEventHook_(#EVENT_OBJECT_FOCUS, #EVENT_OBJECT_VALUECHANGE, #Null, @WinEventFunc(), 0, 0, #WINEVENT_OUTOFCONTEXT|#WINEVENT_SKIPOWNPROCESS)
Repeat
Select WaitWindowEvent(1)
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until quit = 1
CoUninitialize_()
UnhookWinEvent_(eHook)
CloseLibrary(0)
Egypt my love
- Kwai chang caine
- Always Here
- Posts: 5353
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: Get browser URL
Hello RASHAD
Works with FF 63.0.3 (X64)
Thanks for sharing
Believe you if it's possible to use this style of method for writing in the URL ?
I have searching several days for do this without succes
viewtopic.php?f=13&t=71278
Works with FF 63.0.3 (X64)
Thanks for sharing
Believe you if it's possible to use this style of method for writing in the URL ?
I have searching several days for do this without succes
viewtopic.php?f=13&t=71278
The happiness is a road...
Not a destination
Not a destination
Re: Get browser URL
There's plenty of them. One of my own apps, for example, lets you take screenshots and if the foremost window is Firefox, it saves the URL in the image like a watermark. That's one reason.Derren wrote:There's no sensible reason I could think of to read the current browser adress
Re: Get browser URL
maybe that's what you're looking for
Code: Select all
Macro DEFINE_GUID(name, ll, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8):DataSection:name:Data.l ll:Data.w w1:Data.w w2:Data.b b1, b2, b3, b4, b5, b6, b7, b8:EndDataSection:EndMacro
DEFINE_GUID(IID_IHTMLImgElement,$3050f240,$98b5,$11cf,$bb,$82,$0,$aa,$0,$bd,$ce,$0b)
DEFINE_GUID(IID_IHTMLElement,$3050F1FF,$98B5, $11CF,$BB, $82, $00, $AA, $00, $BD, $CE, $0B)
DEFINE_GUID(IID_IHTMLDocument2,$332C4425,$26CB, $11D0 ,$B4, $83, $00, $C0, $4F, $D9, $01, $19 )
DEFINE_GUID(IID_IHTMLInputTextElement,$3050F2A6,$98B5,$11CF,$BB,$82,$00,$AA,$00,$BD,$CE,$0B)
DEFINE_GUID(IID_IHTMLInputButtonElement,$3050F2B2,$98B5,$11CF,$BB,$82,$00,$AA,$00,$BD,$CE,$0B)
Procedure WebGadget_PageIsLoaded(WebBrowser.IWebBrowser2)
Protected READYSTATE_COMPLETE.l
WebBrowser\get_ReadyState(@READYSTATE_COMPLETE)
ProcedureReturn Bool(READYSTATE_COMPLETE=4)
EndProcedure
Procedure WebGadget_getDocument(WebBrowser.IWebBrowser2,Ihtmldocument.IHTMLDocument2)
Protected idh.IDispatch ,ireturn = 0
If WebBrowser
If WebBrowser\get_Document(@idh)=0
If idh\QueryInterface(?IID_IHTMLDocument2,Ihtmldocument)=0
ireturn = 1
Else
idh\Release()
EndIf
EndIf
EndIf
ProcedureReturn ireturn
EndProcedure
Procedure WebGadget_Document_getAllImages(Ihtmldocument.IHTMLDocument2,IDs,List pimge.IHTMLImgElement())
Protected pElement.IHTMLElementCollection, NumItems.l,varName.VARIANT,varIndex.VARIANT,
idh2.IDispatch ,pItem.IHTMLElement ,lpimge.IHTMLImgElement
If Ihtmldocument
If Ihtmldocument\get_all(@pElement)=0
pElement\get_length(@NumItems)
Protected y:For y=0 To NumItems-1
varName\vt = #VT_I4:varName\lVal = y:varIndex\vt = #VT_I4:varIndex\lVal = 1
If pElement\item(varName,varIndex,@idh2)=0
If idh2\QueryInterface(?IID_IHTMLElement, @pItem)=0
If idh2\QueryInterface(?IID_IHTMLImgElement,@lpimge)=0
AddElement(pimge())
PokeI(@pimge(), lpimge)
EndIf
pItem\Release()
EndIf
idh2\Release()
EndIf
Next
pElement\Release()
EndIf
EndIf
EndProcedure
OpenWindow(0,0,0,640,480,"wait load..",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebGadget(0,0,0,640,480, "")
WebBrowser.IWebBrowser2 = GetWindowLong_(GadgetID(0), #GWL_USERDATA)
WebBrowser\Navigate("https://www.purebasic.com/french/index.php",@"",@"",@"",@"")
WebBrowser\put_Silent(#True)
Repeat
WindowEvent()
If WebGadget_PageIsLoaded(WebBrowser)
Break
EndIf
Until EventWindow() = #PB_Event_CloseWindow
htmldocument.IHTMLDocument2
WebGadget_getDocument(WebBrowser,@htmldocument)
NewList HtmlImgElement.IHTMLImgElement()
WebGadget_Document_getAllImages(htmldocument,0,HtmlImgElement())
ForEach HtmlImgElement()
Id = 0
HtmlImgElement()\get_nameProp(@Id)
If Id
Debug "image name : " + PeekS(Id)
EndIf
HtmlImgElement()\get_href(@Id)
If Id
Debug "image link : " + PeekS(Id)
EndIf
HtmlImgElement()\Release()
Next
If htmldocument
htmldocument\Release()
EndIf
If WebBrowser
WebBrowser\Release()
EndIf
interested in Cybersecurity..
Re: Get browser URL
Hi RASHAD,
sorry for the activation of this thread.
I was trying your code, but does not work PB (5.73 LTS 64bit) and Firefox 84.0.1 (64bit)
the code showed an Error on the get_accRole(..) command.
how can I be succesful with your code.
I added some Else Debug stuff to find the problem...
TiA.
sorry for the activation of this thread.
I was trying your code, but does not work PB (5.73 LTS 64bit) and Firefox 84.0.1 (64bit)
the code showed an Error on the get_accRole(..) command.
how can I be succesful with your code.
I added some Else Debug stuff to find the problem...
Code: Select all
Procedure WinEventFunc(HookHandle.l, hEvent.l, hwnd.l, idObject.l, idChild.l, idEventThread.l, dwmsEventTime.l)
Protected *objectIa.IAccessible, a.i=0, b.i=0, c.i=0, d.i=0, e.i=0, f.i=0, g.i=0, h.i=0, i.i=0, j.i=0
Static previousUrl$
Select hEvent
Case #EVENT_OBJECT_FOCUS, #EVENT_OBJECT_VALUECHANGE
className$ = Space(#MAX_PATH)
GetClassName_(hwnd, @className$, #MAX_PATH)
If className$ = "MozillaWindowClass" Or className$ = "Internet Explorer_Server" Or className$ = "IEFrame" Or className$ = "OperaWindowClass"
If CallFunction(0, "AccessibleObjectFromEvent", hwnd, idObject, idChild, @*objectIa, @v.VARIANT) = #S_OK
v.VARIANT\vt = #VT_I4
v\lVal = #CHILDID_SELF
If *objectIa\get_accRole(v, @v) = #S_OK
If v\lVal = #ROLE_SYSTEM_PANE Or v\lVal = #ROLE_SYSTEM_DOCUMENT Or v\lVal = #ROLE_SYSTEM_TEXT
v\vt = #VT_I4
v\lVal = #CHILDID_SELF
url$ = Space(#MAX_PATH)
bstr = @url$
If *objectIa\get_accValue(v, @bstr) = #S_OK
url$ = PeekS(bstr, -1, #PB_Unicode)
If previousUrl$ <> url$ And url$ <> ""
AddGadgetItem(0, -1, url$)
SetClipboardText(url$)
previousUrl$ = url$
EndIf
EndIf
Else :Debug "ERROR: not text, system_Pane, ... "
EndIf
*objectIa\Release()
Else :Debug "ERROR: get_accRole() v = $"+Hex(v\lVal) ;' <-- This occurs on my config.
EndIf
Else :Debug "ERROR: object "
EndIf
EndIf
EndSelect
EndProcedure ;()
Mostly running PureBasic <latest stable version and current alpha/beta> (x64) on Windows 11 Home
Re: Get browser URL
Hi Axolotl
It works as expected
PB 5.73 x86/PB 5.73 x64 - Windows 10 x64 - FF 85 beta
Just run the snippet then run FF and try navigate with different URLs,then report
It works as expected
PB 5.73 x86/PB 5.73 x64 - Windows 10 x64 - FF 85 beta
Just run the snippet then run FF and try navigate with different URLs,then report
Egypt my love
Re: Get browser URL
Hi RASHAD,
sorry for bothering you...
With my debug instruction included for the else-path
I did exactly the steps you wrote:
The result is
Just doing this test on a second computer....
I get the debug line every time I activate FF.
The Listbox-Gadget is remains empty.
Thanks for some help on getting closer to the problem.
Edit: I can navigate to new URLs, move back to existing URLs, nothing happend so far.
sorry for bothering you...
With my debug instruction included for the else-path
I did exactly the steps you wrote:
The result is
Code: Select all
ERROR: get_accRole() v = $0
Just doing this test on a second computer....
I get the debug line every time I activate FF.
The Listbox-Gadget is remains empty.
Thanks for some help on getting closer to the problem.
Edit: I can navigate to new URLs, move back to existing URLs, nothing happend so far.
Mostly running PureBasic <latest stable version and current alpha/beta> (x64) on Windows 11 Home
Re: Get browser URL
I made some further tests (hopefully that helps)
I changed your code to analyse the result:
with the debug output of
which means:
At this stage I am lost (because of no knowledge of IAccessible stuff)
I changed your code to analyse the result:
Code: Select all
;If *objectIa\get_accRole(v, @v) = #S_OK
ret = *objectIa\get_accRole(v, @v)
If ret = #S_OK
with the debug output of
Code: Select all
ERROR: get_accRole() ret = 0x80004003, v = $0
Code: Select all
0x80004003 E_POINTER Pointer that is not valid
Mostly running PureBasic <latest stable version and current alpha/beta> (x64) on Windows 11 Home
Re: Get browser URL
Hi Axolotl
I did some changes to detect from where the errors begin
Test and report
I did some changes to detect from where the errors begin
Test and report
Code: Select all
#CHILDID_SELF = 0
#WINEVENT_OUTOFCONTEXT = 0
#WINEVENT_SKIPOWNPROCESS = $2
#EVENT_OBJECT_FOCUS = $8005
#EVENT_OBJECT_VALUECHANGE = $800E
#ROLE_SYSTEM_DOCUMENT = $F
#ROLE_SYSTEM_PANE = $10
#ROLE_SYSTEM_TEXT = $2A
Global eHook
Procedure WinEventFunc(HookHandle.l, hEvent.l, hwnd.l, idObject.l, idChild.l, idEventThread.l, dwmsEventTime.l)
Protected *objectIa.IAccessible, a.i=0, b.i=0, c.i=0, d.i=0, e.i=0, f.i=0, g.i=0, h.i=0, i.i=0, j.i=0
Static previousUrl$
Select hEvent
Case #EVENT_OBJECT_FOCUS, #EVENT_OBJECT_VALUECHANGE
className$ = Space(#MAX_PATH)
GetClassName_(hwnd, @className$, #MAX_PATH)
If className$ = "MozillaWindowClass" Or className$ = "Internet Explorer_Server" Or className$ = "IEFrame" Or className$ = "OperaWindowClass"
If CallFunction(0, "AccessibleObjectFromEvent", hwnd, idObject, idChild, @*objectIa, @v.VARIANT) = #S_OK
v.VARIANT\vt = #VT_I4
v\lVal = #CHILDID_SELF
If *objectIa\get_accRole(v, @v) = #S_OK
If v\lVal = #ROLE_SYSTEM_PANE Or v\lVal = #ROLE_SYSTEM_DOCUMENT Or v\lVal = #ROLE_SYSTEM_TEXT
v\vt = #VT_I4
v\lVal = #CHILDID_SELF
url$ = Space(#MAX_PATH)
bstr = @url$
If *objectIa\get_accValue(v, @bstr) = #S_OK
url$ = PeekS(bstr, -1, #PB_Unicode)
If previousUrl$ <> url$ And url$ <> ""
AddGadgetItem(0, -1, url$)
SetClipboardText(url$)
previousUrl$ = url$
EndIf
EndIf
EndIf
*objectIa\Release()
Else
MessageRequester("Error","get_accRole Error ",#MB_OK|#MB_ICONERROR)
EndIf
EndIf
EndIf
EndSelect
EndProcedure
OpenWindow(0, 550, 450, 500, 500, "Get Browser URL", #PB_Window_MinimizeGadget)
ListViewGadget(0, 10, 10, 480, 480)
CoInitialize_(0)
hdll = OpenLibrary(0, "Oleacc.dll")
If hdll
eHook = SetWinEventHook_(#EVENT_OBJECT_FOCUS, #EVENT_OBJECT_VALUECHANGE, #Null, @WinEventFunc(), 0, 0, #WINEVENT_OUTOFCONTEXT|#WINEVENT_SKIPOWNPROCESS)
If eHook = 0
MessageRequester("Error","Unsuccessful Hooking",#MB_OK|#MB_ICONERROR)
EndIf
Else
MessageRequester("Error","The DLL not loaded ",#MB_OK|#MB_ICONERROR)
EndIf
Repeat
Select WaitWindowEvent(1)
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until quit = 1
CoUninitialize_()
UnhookWinEvent_(eHook)
CloseLibrary(0)
Egypt my love
Re: Get browser URL
Hi RASHAD,
thanks for your help.
I had done that already - maybe I made some mistakes to show you the right results.
Here is the entire code (with my changes)
BTW: Cannot close your program, because of the messagerequester which always pops up.
I have the result of the failing function:
ret = *objectIa\get_accRole(v, @v) this ret is 0x80004003 E_POINTER Pointer that is not valid acc. to microsoft
thanks for your help.
I had done that already - maybe I made some mistakes to show you the right results.
Here is the entire code (with my changes)
BTW: Cannot close your program, because of the messagerequester which always pops up.
I have the result of the failing function:
ret = *objectIa\get_accRole(v, @v) this ret is 0x80004003 E_POINTER Pointer that is not valid acc. to microsoft
Code: Select all
#CHILDID_SELF = 0
#WINEVENT_OUTOFCONTEXT = 0
#WINEVENT_SKIPOWNPROCESS = $2
#EVENT_OBJECT_FOCUS = $8005
#EVENT_OBJECT_STATECHANGE = $800A ;' added
#EVENT_OBJECT_LOCATIONCHANGE= $800B ;' added
#EVENT_OBJECT_NAMECHANGE = $800C ;' added
#EVENT_OBJECT_VALUECHANGE = $800E
#ROLE_SYSTEM_DOCUMENT = $F
#ROLE_SYSTEM_PANE = $10
#ROLE_SYSTEM_TEXT = $2A
; Prototype.l ProtoAccessibleObjectFromEvent(hWnd, dwId, dwChildId, *ppAcc, *pVarChild)
; ; HRESULT AccessibleObjectFromEvent(
; ; HWND hwnd,
; ; DWORD dwId,
; ; DWORD dwChildId,
; ; IAccessible **ppacc,
; ; VARIANT *pvarChild
; ; );
; Global AccessibleObjectFromEvent.ProtoAccessibleObjectFromEvent
Procedure WinEventFunc(HookHandle.l, hEvent.l, hwnd.l, idObject.l, idChild.l, idEventThread.l, dwmsEventTime.l)
Protected *objectIa.IAccessible, a.i=0, b.i=0, c.i=0, d.i=0, e.i=0, f.i=0, g.i=0, h.i=0, i.i=0, j.i=0
Static previousUrl$
Protected ret ;' new by Axolotl
Select hEvent
Case #EVENT_OBJECT_FOCUS, #EVENT_OBJECT_VALUECHANGE
className$ = Space(#MAX_PATH)
GetClassName_(hwnd, @className$, #MAX_PATH)
If className$ = "MozillaWindowClass" Or className$ = "Internet Explorer_Server" Or className$ = "IEFrame" Or className$ = "OperaWindowClass" :Debug "> Classname = "+className$
Debug "> hWnd = "+hwnd+", idObject = "+idObject+", idChild = "+idChild
If CallFunction(0, "AccessibleObjectFromEvent", hwnd, idObject, idChild, @*objectIa, @v.VARIANT) = #S_OK ; And *objectIa <> #Null ;' added
v.VARIANT\vt = #VT_I4
v\lVal = #CHILDID_SELF
;If *objectIa\get_accRole(v, @v) = #S_OK
ret = *objectIa\get_accRole(v, @v)
If ret = #S_OK
If v\lVal = #ROLE_SYSTEM_PANE Or v\lVal = #ROLE_SYSTEM_DOCUMENT Or v\lVal = #ROLE_SYSTEM_TEXT
v\vt = #VT_I4
v\lVal = #CHILDID_SELF
url$ = Space(#MAX_PATH)
bstr = @url$
If *objectIa\get_accValue(v, @bstr) = #S_OK
url$ = PeekS(bstr, -1, #PB_Unicode)
If previousUrl$ <> url$ And url$ <> ""
AddGadgetItem(0, -1, url$)
SetClipboardText(url$)
previousUrl$ = url$
EndIf
EndIf
Else :Debug "> ERROR: not text, system_Pane, ... "
EndIf
*objectIa\Release()
Else :Debug "> ERROR: get_accRole() ret = 0x"+Hex(ret)+", v = $"+Hex(v\lVal)
EndIf
Else :Debug "> ERROR: object "
EndIf
EndIf
Case #EVENT_OBJECT_STATECHANGE To #EVENT_OBJECT_NAMECHANGE
; do nothing here
Default :Debug "> hEvent = 0x"+Hex(hEvent)
EndSelect
EndProcedure ;()
OpenWindow(0, 550, 450, 500, 500, "Get Browser URL", #PB_Window_MinimizeGadget) :Debug "MainWin = 0x"+Hex(WindowID(0))+" ("+Str(WindowID(0))+")"
ListViewGadget(0, 10, 10, 480, 480)
CoInitialize_(0)
hdll = OpenLibrary(0, "Oleacc.dll") :Debug "hdll = "+hdll
; AccessibleObjectFromEvent = GetFunction(hdll, "AccessibleObjectFromEvent")
eHook = SetWinEventHook_(#EVENT_OBJECT_FOCUS, #EVENT_OBJECT_VALUECHANGE, #Null, @WinEventFunc(), 0, 0, #WINEVENT_OUTOFCONTEXT|#WINEVENT_SKIPOWNPROCESS) :Debug "eHook = "+eHook
Repeat
Select WaitWindowEvent(1)
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until quit = 1
CoUninitialize_()
UnhookWinEvent_(eHook)
CloseLibrary(0)
Mostly running PureBasic <latest stable version and current alpha/beta> (x64) on Windows 11 Home
Re: Get browser URL
Hi Axolotl
Sorry for my stupid Message Requester
You did not mention your OS and version
We are on the track
Keep moving
Sorry for my stupid Message Requester
You did not mention your OS and version
We are on the track
Keep moving
Egypt my love