Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tweak GetChildObjects routine
#1
Hello,

i have alittle problem with this code given in Acc.GetChildObjects help.

get name/URL of all Firefox tabs
int w=win("Mozilla Firefox" "Mozilla*WindowClass" "" 0x804)
Acc a.Find(w "DOCUMENT" "" "" 0x3010 2 0 "parent3") ;;find current DOCUMENT and get its parent GROUPING
ARRAY(Acc) b; int i
a.GetChildObjects(b 2 "DOCUMENT" "" "" 16) ;;get all child DOCUMENT at level 2, including hidden
for i 0 b.len
out "--------"
out b[i].Name ;;page name
out b[i].Value ;;page URL
if(b[i].State&STATE_SYSTEM_INVISIBLE=0) out "<visible>"

I found it working perfectly as long as a web page has content, empty DOCUMENT webpage throw exception , which is normal due to the 0x3010 flag.

For example, my firefox homepage is Speed dial, which have an APPLICATION property in place of DOCUMENT. If I test the above code with a tab containig speeddial page
it does not work.

I'd like the code to skip the first faulty tab, and begin enumeration from another tab which does have a DOCUMENT property to retreive all tabs.

In fact, it's a short version of the problem which actually reside in the FirefoxGetTabs , but the solution for this one should apply to it too.

Possible?

Thanks.
#2
Change flags to 0x1010. Slower but works.
With flag 0x2000, finds root object of current web page. It is fast, because goes directly to the object. However fails if root object of current page is not DOCUMENT, if DOCUMENT is specified.
Without the flag, searches all object three until finds a DOCUMENT, therefore is slow.

This also works, and is fast. Will not work if current page is completely empty, but i never saw such web pages in Firefox.
Macro Macro1862
Code:
Copy      Help
Acc a.Find(w "" "" "" 0x3010 0 0 "parent4") ;;find first object in current web page and get its parent GROUPING
#3
Gintaras Wrote:Change flags to 0x1010. Slower but works.]

Yes solve the problem, did try many flags variations, but not this one....

Gintaras Wrote:With flag 0x2000, finds root object of current web page. It is fast, because goes directly to the object. However fails if root object of current page is not DOCUMENT, if DOCUMENT is specified.
Without the flag, searches all object three until finds a DOCUMENT, therefore is slow.

This one fails.

Gintaras Wrote:This also works, and is fast. Will not work if current page is completely empty, but i never saw such web pages in Firefox.
Macro Macro1862
Code:
Copy      Help
Acc a.Find(w "" "" "" 0x3010 0 0 "parent4") ;;find first object in current web page and get its parent GROUPING

This one works in tweaking Acc.GetChildObjects, fails with FirefoxGetTabs. I think I must modify some navigation function parameters in it.

Thanks, briallant support as always.
#4
Acc a.Find(w "" "" "" 0x3010 0 0 "parent4")
Don't use this. In next QM it will find the root object, and this code will not work. It is a bug if it does not find the root object if role is not specified, and will be fixed. Wait, I'll give something better.
#5
Member function Acc.FindFirefoxWebRoot
Code:
Copy      Help
function `hwnd

;Gets root object of current web page in Firefox.


#if QMVER<0x2030400
Find(hwnd "" "" "" 0x3000 0 0 "parent")
#else
Find(hwnd "" "" "" 0x3000)
#endif

err+ end _error

Example. Replaced only the Acc a.Find... line.
Macro Macro1862
Code:
Copy      Help
out
;get name/URL of all Firefox tabs
int w=win("Mozilla Firefox" "Mozilla*WindowClass" "" 0x804)
Acc a.FindFirefoxWebRoot(w); a.Navigate("parent3")
ARRAY(Acc) b; int i
a.GetChildObjects(b 2 "DOCUMENT" "" "" 16) ;;get all child DOCUMENT at level 2, including hidden
for i 0 b.len
,out "--------"
,out b[i].Name ;;page name
,out b[i].Value ;;page URL
,if(b[i].State&STATE_SYSTEM_INVISIBLE=0) out "<visible>"

In FirefoxGetTabs replace line a.Find(hwndFF "DOCUMENT"... with:
Function FirefoxGetTabs
Code:
Copy      Help
a.FindFirefoxWebRoot(hwndFF); a.Navigate("pa3fi")
#6
Well, the new code is blazing fast, works for APPLICATION node replacing DOCUMENT, but not when "browser" property has no child.

I embed a picture to make things clearer.

Any fix??


Attached Files Image(s)
   
#7
Can get URL only of loaded pages. New Firefox versions don't load pages in invisible tabs at startup.
#8
Gintaras Wrote:Can get URL only of loaded pages. New Firefox versions don't load pages in invisible tabs at startup.

Yes I fully understand that. I just want the FirefoxGetTabs be able to skip the tab that contains no DOCUMENT property in iteration, so it does not
appears in list, and without generating any error. I don't have the use of empty webpage.


Quote:
Code:
Copy      Help
rep
     get id of this pane, and find in ap
    fn.FromAcc(a); _s=fn.Attribute("id")
    for(i 0 ap.len) if(ap[i]=_s) break
    if(i=names.len) goto next2 ;;should never happen
     get DOCUMENT object and url
    Acc aa; a.Navigate("fi2" aa)
    if(&urls) urls[i]=aa.Value
    if(&docObjects) docObjects[i]=aa
    
     next2
    a.Navigate("n"); err break

ret r

In this, if document not present, then I have logically a "object not found" error, terminating the routine (as asked by the code, no problem here).
I'd like to continue iteration of through other tabs and discard the empty one.

Possible?
#9
To be much simplier:

If code

Code:
Copy      Help
a.FindFirefoxWebRoot(hwndFF); a.Navigate("pa3fi")
fails because the current selected tab from which iteration through tab set begins, how to begin with another one, until I find a
valid one containing DOCUMENT property?
#10
It worked with all tabs, but now error after restarting Firefox. Did not test with non-loaded tabs.

Replace
,Acc aa; a.Navigate("fi2" aa)
with
Function FirefoxGetTabs
Code:
Copy      Help
,Acc aa; a.Navigate("fi2" aa); err goto next2
#11
Found the same thing while trying by myself.

Only issue is the new function

Code:
Copy      Help
a.FindFirefoxWebRoot(hwndFF); a.Navigate("pa3fi")

does not work there, genereta error with empty page.

Code:
Copy      Help
a.Find(hwndFF "DOCUMENT" "" "" 0x1010 2 0 "pa3fi")  <====================reverted to that (the new function does not work, generate error)
rep
     get id of this pane, and find in ap
    fn.FromAcc(a); _s=fn.Attribute("id")
    for(i 0 ap.len) if(ap[i]=_s) break
    if(i=names.len) goto next2 ;;should never happen
     get DOCUMENT object and url
    Acc aa; a.Navigate("fi2" aa)
                        err goto next2 ;; <==================== added this to bypass the aa object not existing
    if(&urls) urls[i]=aa.Value
    if(&docObjects) docObjects[i]=aa
    
     next2
    a.Navigate("n"); err break

ret r

err+ end _error


Hope this good behavior will last.
#12
Try this version.
Member function Acc.FindFirefoxWebRoot
Code:
Copy      Help
function hwnd

;Gets root object of current web page in Firefox.

FromWindow(hwnd OBJID_CLIENT)
VARIANT v=a.Navigate(0x1009 1)
a=v.pdispVal

err+ end _error
#13
or replace the a.Find(hwndFF "DOCUMENT" ... line with
Function FirefoxGetTabs
Code:
Copy      Help
#if QMVER<0x2030400
a.Find(hwndFF "DOCUMENT" "" "" 0x3000 0 0 "pa3fi")
err
,a.Find(hwndFF "DOCUMENT" "" "" 0x1010 1 0 "pa3fi")
,err a.Find(hwndFF "" "" "" 0x3010 1 0 "pa4fi")
#else
a.Find(hwndFF "" "" "" 0x3000 2 0 "pa3fi")
#endif
It will be slower only if current tab is "New Tab" (no "DOCUMENT")

or
Function FirefoxGetTabs
Code:
Copy      Help
#if QMVER<0x2030400
a.Find(hwndFF "DOCUMENT" "" "" 0x3000 0 0 "pa3fi")
err a.Find(hwndFF "" "" "" 0x3010 1 0 "pa4fi")
#else
a.Find(hwndFF "" "" "" 0x3000 2 0 "pa3fi")
#endif
#14
Gintaras Wrote:Try this version.
Member function Acc.FindFirefoxWebRoot
Code:
Copy      Help
function hwnd

;Gets root object of current web page in Firefox.

FromWindow(hwnd OBJID_CLIENT)
VARIANT v=a.Navigate(0x1009 1)
a=v.pdispVal

err+ end _error

Fails with this error : Error (RT) in FirefoxUrlFromTabName: 0x80004005, no specified error. ?

Gintaras Wrote:or replace the a.Find(hwndFF "DOCUMENT" ... line with
Function FirefoxGetTabs
Code:
Copy      Help
#if QMVER<0x2030400
a.Find(hwndFF "DOCUMENT" "" "" 0x3000 0 0 "pa3fi")
err
,a.Find(hwndFF "DOCUMENT" "" "" 0x1010 1 0 "pa3fi")
,err a.Find(hwndFF "" "" "" 0x3010 1 0 "pa4fi")
#else
a.Find(hwndFF "" "" "" 0x3000 2 0 "pa3fi")
#endif

It will be slower only if current tab is "New Tab" (no "DOCUMENT")
Works but much slower than previous version

or
Quote:
Code:
Copy      Help
Function [b]FirefoxGetTabs[/b] [help1][/help1]
[code]#if QMVER<0x2030400
a.Find(hwndFF "DOCUMENT" "" "" 0x3000 0 0 "pa3fi")
err a.Find(hwndFF "" "" "" 0x3010 1 0 "pa4fi")
#else
a.Find(hwndFF "" "" "" 0x3000 2 0 "pa3fi")
#endif

Fails : Error (RT) in FirefoxUrlFromTabName: object not found. ?


Forum Jump:


Users browsing this thread: 1 Guest(s)