AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

FF javascript via COM
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
ahklerner



Joined: 26 Jun 2006
Posts: 1205
Location: USA

PostPosted: Tue Dec 11, 2007 1:43 am    Post subject: FF javascript via COM Reply with quote

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
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1336

PostPosted: Tue Dec 11, 2007 2:33 am    Post subject: Reply with quote

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
View user's profile Send private message
ahklerner



Joined: 26 Jun 2006
Posts: 1205
Location: USA

PostPosted: Tue Dec 11, 2007 4:01 am    Post subject: Reply with quote

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
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1336

PostPosted: Tue Dec 11, 2007 5:11 am    Post subject: Reply with quote

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
View user's profile Send private message
ahklerner



Joined: 26 Jun 2006
Posts: 1205
Location: USA

PostPosted: Thu Dec 13, 2007 6:19 am    Post subject: Reply with quote

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? Question
_________________
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1336

PostPosted: Thu Dec 13, 2007 11:29 am    Post subject: Reply with quote

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? Question

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
View user's profile Send private message
ahklerner



Joined: 26 Jun 2006
Posts: 1205
Location: USA

PostPosted: Fri Dec 21, 2007 3:45 am    Post subject: Reply with quote

DANG IT. I wish that would work. Oh well.

Thanks Sean.
_________________
Back to top
View user's profile Send private message
Erittaf



Joined: 03 Nov 2007
Posts: 182

PostPosted: Sat Dec 22, 2007 3:49 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
nekko



Joined: 25 Sep 2007
Posts: 56
Location: Los Angeles, CA

PostPosted: Tue Feb 05, 2008 2:38 am    Post subject: Reply with quote

Someone who has the skills please develop a function for this.
Back to top
View user's profile Send private message AIM Address
nekko



Joined: 25 Sep 2007
Posts: 56
Location: Los Angeles, CA

PostPosted: Tue Feb 05, 2008 2:54 am    Post subject: Reply with quote

I did some snooping around and found this page. Might shed some light on this topic. http://blogs.msdn.com/drewmiller/archive/2007/12/08/adventures-in-automation-firefox-part-i.aspx
Back to top
View user's profile Send private message AIM Address
Lexikos



Joined: 17 Oct 2006
Posts: 2558
Location: Australia, Qld

PostPosted: Tue Feb 05, 2008 8:53 am    Post subject: Reply with quote

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
View user's profile Send private message
nekko



Joined: 25 Sep 2007
Posts: 56
Location: Los Angeles, CA

PostPosted: Tue Feb 19, 2008 1:13 am    Post subject: Reply with quote

Here are some more helpful links. Using python to automate Firefox. http://ldtp.freedesktop.org/wiki/Firefox_Test_Cases

And a IE and FF automation program http://www.autohotkey.com/
Back to top
View user's profile Send private message AIM Address
ahklerner



Joined: 26 Jun 2006
Posts: 1205
Location: USA

PostPosted: Tue Feb 19, 2008 3:26 am    Post subject: Reply with quote

nekko wrote:
And a IE and FF automation program http://www.autohotkey.com/

You do realize the forum you are on, right?
_________________
Back to top
View user's profile Send private message
nekko



Joined: 25 Sep 2007
Posts: 56
Location: Los Angeles, CA

PostPosted: Tue Feb 19, 2008 4:33 am    Post subject: Reply with quote

Doh' posted the link in clipboard at the time... here is the link http://artoftest.com/
Back to top
View user's profile Send private message AIM Address
AtWork
Guest





PostPosted: Tue Feb 19, 2008 1:17 pm    Post subject: Reply with quote

You can use the free iMacros for Firefox extension to automate Firefox VERY easily. It can be combined with AutoHotkey, too Very Happy

http://www.iopus.com/imacros/firefox/

Integrate with AHK with the run.imacros.net command line:
http://wiki.imacros.net/iMacros_for_Firefox#Command_Line_Support
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group