| View previous topic :: View next topic |
| Author |
Message |
ahklerner
Joined: 26 Jun 2006 Posts: 1205 Location: USA
|
Posted: Tue Dec 11, 2007 1:43 am Post subject: FF javascript via COM |
|
|
I am trying to mod the IE javascript function to work with Firefox.
Here is what I have so far:
| Code: | FF_InjectJS(hWnd_MainWindow, JS_to_Inject, VarNames_to_Return="")
{
;Get a list of the hWnd's owned by the window specified
WinGet, ActiveControlList, ControlListhWnd, ahk_id %hWnd_MainWindow%
;Go throught the list 1 at a time to determine if it is the correct control
;This will allow the script to find the current tab in FF
Loop, Parse, ActiveControlList, `n
{
;Get the classname of the current control
WinGetClass, ThisWinClass, ahk_id %A_LoopField%
;If the classname is correct and it is visible, it is the correct tab
;MsgBox, %ThisWinClass%
If (ThisWinClass = "MozillaContentWindowClass") and (DllCall("IsWindowVisible", UInt, A_LoopField)) {
hFFSvr := A_LoopField
}
}
;If a control was not found, give a message and return, doing nothing
If !hFFSvr
{
MsgBox, Control "MozillaContentWindowClass" not found.
Return
}
;Initialize the COM interface. code modified from SEAN
IID_IHTMLWindow2 := "{D30C1661-CDAF-11D0-8A3E-00C04FC9E26E}"
ACC_Init()
pacc := ACC_AccessibleObjectFromWindow(hFFSvr)
pwin := COM_QueryService(pacc,IID_IHTMLWindow2,IID_IHTMLWindow2)
MsgBox % "pWin-" . pWin
; MsgBox % COM_Invoke(pacc, "accNavigate", "http://www.google.com") ; JS_to_Inject)
COM_Release(pacc)
;Execute the Javascript (if there is any). Thanks LEXIKOS.
If JS_to_Inject
MsgBox % COM_Invoke(pwin, "accNavigate", "http://www.google.com") ; JS_to_Inject)
;Get the value of the variables, if any.
If VarNames_to_Return {
;Split the passed variable names into a psuedo array of ahk variables
StringSplit, Vars_, VarNames_to_Return, `,
;Get the value of each javascript variable in the order it was passed
Loop, %Vars_0%
Ret .= COM_Invoke(pwin,Vars_%A_Index%) . ","
;Remove the trailing comma
StringTrimRight, Ret, Ret, 1
}
; Cleanup
COM_Release(pwin)
ACC_Term()
;Return a comma seperated list of variables in the order they were passed
Return Ret
}
|
Can someone tell me what is wrong? _________________
 |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1336
|
Posted: Tue Dec 11, 2007 2:33 am Post subject: |
|
|
| Firefox doesn't implement any COM Server, i.e., it doesn't have IHTMLWindow2 interface. Even its support for Accessibility appeared very basic. It was the reason I wrote a separate ACC.ahk, which would have been unnecessary otherwise. |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1205 Location: USA
|
Posted: Tue Dec 11, 2007 4:01 am Post subject: |
|
|
This uses your acc.ahk. I also replaced the guid (?) with the one daonlyfreez used for initializing a mozilla browser control. I also saw the accNavigate and attempt to use it here, but am not sure if I am doing it correctly.
This line
| Code: | MsgBox % "pWin-" . pWin
|
does return a value, so is it working correctly?
I do not really understand the inner workings of COM. How would you do this? _________________
 |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1336
|
Posted: Tue Dec 11, 2007 5:11 am Post subject: |
|
|
| ahklerner wrote: | This line
| Code: | MsgBox % "pWin-" . pWin
|
does return a value, so is it working correctly? |
That won't work with Firefox, which I meant by "it doesn't have IHTMLWindow2 interface". It'll work up to only obtaining pacc.
What I meant by "Even its support for Accessibility appeared very basic" was that even obtaining pacc (of child) sometimes failed with the usual method for Firefox.
| Quote: | | I do not really understand the inner workings of COM. How would you do this? |
I'm not sure of what you really meant. Is it a COM related question, or one specific in this firefox case? Accessibility provides some methods which might be applicable in this case, like acc_HitTest(), acc_Navigate() etc. However, MSDN says Put Name/Value is obsolete. If it really is, then I'm afraid they'll end in vain after all. But I haven't tried acc_Name_() and acc_Value_() yet. |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1205 Location: USA
|
Posted: Thu Dec 13, 2007 6:19 am Post subject: |
|
|
I was asking how you would navigate to a web page in firefox. Also want to be able to inject js like in my IE script.
Possible?  _________________
 |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1336
|
Posted: Thu Dec 13, 2007 11:29 am Post subject: |
|
|
| ahklerner wrote: | I was asking how you would navigate to a web page in firefox. Also want to be able to inject js like in my IE script.
Possible?  |
No, with the native Firefox. I tested Put Name/Value and it didn't work as MSDN says.
If you install Mozilla ActiveX, I suppose you could use WebBrowser control to do it, but I haven't tested it myself.
However, you can't still use the method of IHTMLWindow2 etc for already running instances of Firefox. |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1205 Location: USA
|
Posted: Fri Dec 21, 2007 3:45 am Post subject: |
|
|
DANG IT. I wish that would work. Oh well.
Thanks Sean. _________________
 |
|
| Back to top |
|
 |
Erittaf
Joined: 03 Nov 2007 Posts: 182
|
Posted: Sat Dec 22, 2007 3:49 am Post subject: |
|
|
Well it seems that this idea kinda died, but I am definitely interested in working out a solution. I unfortunately have little time to go through MSDN, however I have a ton of applications that would benefit from being able to inject mozilla with Javascript. The only way I have to do it right now is by sending it to the address bar but this is not the best solution as my end users start thinking they have a virus or something.
Anyway, looking through the forums I see a lot of things that AHK could "never do" long ago that it now can do. This seems like one of those items that we can figure out if we put our heads together!
Long post made short: Please don't abandon this train of thought... there must be a solution! |
|
| Back to top |
|
 |
nekko
Joined: 25 Sep 2007 Posts: 56 Location: Los Angeles, CA
|
Posted: Tue Feb 05, 2008 2:38 am Post subject: |
|
|
| Someone who has the skills please develop a function for this. |
|
| Back to top |
|
 |
nekko
Joined: 25 Sep 2007 Posts: 56 Location: Los Angeles, CA
|
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2558 Location: Australia, Qld
|
Posted: Tue Feb 05, 2008 8:53 am Post subject: |
|
|
| UI Automation (aka MUIA, see nekko's link) would allow you to detect text and click links in the active tab and manipulate the window itself, but that's about it. Detecting text and clicking links can probably also be done with Active Accessibility, which unlike UI Automation, doesn't require the .NET Framework. |
|
| Back to top |
|
 |
nekko
Joined: 25 Sep 2007 Posts: 56 Location: Los Angeles, CA
|
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1205 Location: USA
|
Posted: Tue Feb 19, 2008 3:26 am Post subject: |
|
|
You do realize the forum you are on, right? _________________
 |
|
| Back to top |
|
 |
nekko
Joined: 25 Sep 2007 Posts: 56 Location: Los Angeles, CA
|
Posted: Tue Feb 19, 2008 4:33 am Post subject: |
|
|
| Doh' posted the link in clipboard at the time... here is the link http://artoftest.com/ |
|
| Back to top |
|
 |
AtWork Guest
|
|
| Back to top |
|
 |
|