Jump to content

Recommended Posts

Posted (edited)

Greetings,

Is possible build a script to send/receive commands in "Native Messagin" ?

If you install this extension:
https://chrome.google.com/webstore/detail/native-messaging-example/mefhabneoickhhbiglkmehhmemefkopf/related

And this complement:
https://github.com/Mandar-Shinde/Google-Chrome-Native-Messaging/releases/download/V1.0/GoogleNativeClient.exe

You have a work example to send / receive messages from Google Chrome's plugin and NativeMessagingApp.exe.

I found the source NativeMessagingApp.exe's here:
https://github.com/Mandar-Shinde/Google-Chrome-Native-Messaging

I try build this script... But not work...
 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Outfile=C:\Users\Public\GoogleNativeClient\NativeMessagingApp2.exe
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#NoTrayIcon

#include-once
#include <Array.au3>
#include <JSMN.au3> ; https://github.com/chechelaky/AutoIt/blob/master/JSMN.au3
#include <Debug.au3>

Global $msg = "@empty"

Global Const $CLIENT_START = '{"text":"Client Started"}'
Global Const $CLIENT_STOP = '{"text":"Client Stopped"}'
Global Const $CLIENT_CLICK = '{"text":"Client Click"}'

_DebugSetup("NativeMessagingApp2", True, 4, @ScriptDir & "\NativeMessagingApp2.log", True)

Global $read, $json, $out = ""

If IsArray($CmdLine) Then
;~  $msg = @LF & "Google Chrome Native Messaging App V1" & @LF & @LF & _
;~          "GPLV3 software distributed under the License is distributed on an ""AS IS"" BASIS" & @LF & _
;~          "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." & @LF & _
;~          "See the License for the specific language governing permissions and" & @LF & _
;~          "limitations under the License." & @LF & @LF

;~  Local $size = UBound($CmdLine, 1) - 1
;~  $msg &= "App running with args=" & $size & @LF
;~  For $ii = 0 To $size
;~      $msg &= $ii & " : " & $CmdLine[$ii] & @LF
;~  Next
;~  _DebugOut($msg)
EndIf

sendMessage($CLIENT_START)

While Sleep(10)
    $read = ConsoleRead()
    If @error And $out Then
        _DebugOut("$read...............: " & $out)
        $json = Jsmn_decode($out)
        If @error Then
            _DebugOut("$json...............: @Error")
        Else
            _DebugOut("$json...............: @Ok")
        EndIf

        If IsObj($json) And $json.Exists("text") Then
            sendMessage('{"text":"' & $json.Item("text") & '"}')
        Else
            sendMessage('{"text":"@Error"}')
        EndIf
        $out = ""
    Else
        $out &= $read
    EndIf
WEnd

Func sendMessage($var)
    ConsoleWrite($var & @CRLF)
    _DebugOut("sendMessage===>" & $var)
EndFunc   ;==>Say

 

Edit the file:
C:\Users\Public\GoogleNativeClient\com.google.chrome.example.echo-win.json

And replace:
"path": "NativeMessagingApp.exe",

By:
"path": "NativeMessagingApp2.exe",

Then plugin call the AutoIt script...

But is not functional...

 

About the file mainwindow.cpp, have this function:

inline QString sendMessage(QString data){
  unsigned int len = data.length();
  cout.write(reinterpret_cast<const char *>(&len), 4);
  cout << data.toUtf8().data() << flush;
  return "";
}

How re-write this to AutoIt?
How execute a flush?



Best regards.

Edited by Luigi

Share this post


Link to post
Share on other sites
Posted (edited)

https://www.autoitscript.com/autoit3/docs/functions/StdoutRead.htm

https://www.autoitscript.com/autoit3/docs/functions/StdinWrite.htm

https://www.autoitscript.com/autoit3/docs/functions/StdioClose.htm

flush most likely not needed 

https://www.autoitscript.com/autoit3/docs/functions/FileFlush.htm

 

although I would expect consoleread/consolewrite should be able to do what you need.

step 1 would be that you see the plugin from chrome starts your compiled exe. you should be able to see that happening with a simple gui window or thru taskmanager

 

Edited by junkew

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By Danyfirex
      Hello guys.  It's been awhile since I shared something. So today I want to share my last project.
      What's Loga?
      Loga is a simple logging library to keep track of code with an integrated console.
      Features.
      Common log levels. Integrated console. Multiple instances. Custom color and font for each instance log level. Define output format with macros. Conditional and occasional Logging. Easy to use. Basic Usage:
      #include "..\Loga.au3" ;This are some of the default settings: ;Default log level $LOGA_LEVEL_TRACE ;output format: {Symbol}{LogIndex} {LevelName} {LongDateTime} {Message} ;Log to File is enabled. ;Log file name format: YYYYMMDDHHMM-Loga-InstanceIndex.log ;Custom Console is disabled by default. ;By default log to STDOUT. _LogaTrace("I'm Trace") _LogaDebug("I'm Debug") _LogaInfo("I'm Info") _LogaWarn("I'm Warn") _LogaError("I'm Error") _LogaFatal("I'm Fatal")  
      More examples here.
       
      Check Loga on GitHub.
       
      Loga Latest Release v1.0.2.
       
      Saludos
       
       
       
       
    • By gahhon
      I am not very sure if I am all right to post here tho. Due to other forums have no respond at all.
      So I have my custom make google chrome extension, and it will load unpack into Portable Google Chrome, but it keep pop up the alert box

      Is there any way to disable it? Because my Portable Google Chrome will load as Kiosk mode, so that user can't be uninstall/disable the extension.
      Many thanks in advance.
    • By xuzo
      Haven't used AutoIt in years, so very rusty...
      I can make autoIT activate windows of different programs, but having a hard time getting it to activate different tabs on Google chrome.
      It only works if the window is open and all other tabs are closed.
      #include <Constants.au3> #include <AutoItConstants.au3> Opt("WinTitleMatchMode", 2) WinActivate ( "Calc" ) WinWait("Calc") MouseClick($MOUSE_CLICK_LEFT, 100, 200, 2) send("{shiftdown}{end}{shiftup}{ctrlDown}c{ctrlUp}") $title = ClipGet() ;send($title) ;this is the section where I would like a specific tab to be activated WinActivate ( "Create +Prospects | Simple CRM - Cent Browser" ) WinWait("Create +Prospects | Simple CRM - Cent Browser") ;Opt("WinTitleMatchMode", 1) ;Local $hWnd= WinWait("Simple") ;WinActivate($hWnd) MouseClick($MOUSE_CLICK_LEFT, 300, 500, 2) Send($title)  
    • By Seminko
      I use Chrome's 'Translate this page' functionality quite a lot at work. My workflow is usually translating the page to english so I know what it is about, finding correct lines, translating it back to the original language so I can grab the correct XPath (since translating it, updates the structure and most importantly the text displayed, obviously), and rinse and repeat.
      Since I do it all the time, each unnecessary click in the end amounts to quite some time I would rather be spending actually working. You have to click the translate button, it asks whether you want to translate the page, you have to click yes. Then sometimes the little window is in the way so you click it off but when you need to translate back to the original language you have to click the little icon again.
      How would one go about automating it?
      Checked the forum and it seems that the old Chrome UDF doesn't work and the best way for interacting with Chrome is the WebDriver UDF which, from what I've read and tested a bit, creates a new, different instance of Chrome.
      I tried using the good old MouseClick but I don't find it reliable. Also ControlClick seems to be out of the picture since the whole Chrome window is "one single control".
      Any ideas are appreciated.
    • By boomingranny
      Use this UDF to add a console gui to your script (with log file):
      It uses the Hidden Autoit window (that you probably didn't even know existed)
      Closing Console window will terminate script.
      example of console:

      #include-once #include <GuiEdit.au3> EnableConsoleGui("example.log") ;example: ;------------------------ ConsoleWrite ("Hello World") For $i = 1 To 10 ConsoleWrite (".") Sleep(200) Next ConsoleWrite ("done") ConsoleWrite(@CRLF) ConsoleWrite ("close me to exit"&@CRLF) While 1 Sleep(1000) WEnd ;------------------------ ;end of example code Func EnableConsoleGui($Logfile="") ;EnableConsoleGUI ;by Daniel Barnes 20/04/2018 ;Uses AutoIt's Hidden window as a console (output only) Global $pidChild ;if we don't have a parent (as the parent window would have our script name) If Not WinExists(StringTrimRight(@ScriptName,4)) Then Opt("TrayIconHide",1) ;get Autoit's hidden window handle local $hWnd = WinGetHandle(AutoItWinGetTitle()) ;move the autoit hidden window to the middle of the screen WinMove($hWnd, "", (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ;get the Handle of the edit box in Autoit's hidden window $hEditBox = ControlGetHandle($hWnd,"","[CLASS:Edit; INSTANCE:1]") ;show it WinSetState($hWnd, "", @SW_SHOW) ;set its title = our script name WinSetTitle($hWnd,"",StringTrimRight(@ScriptName,4)) ;Spawn a child "copy" of the script, enabling reading of its console... If @Compiled Then ;2 = $STDOUT_CHILD. This avoids requiring the AutoItConstants.au3 in this sample code $pidChild= Run( FileGetShortName(@ScriptFullPath),@ScriptDir,"",2) Else ;2 = $STDOUT_CHILD. This avoids requiring the AutoItConstants.au3 in this sample code $pidChild= Run( FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath),@ScriptDir,"",2) EndIf OnAutoItExitRegister("EnableConsoleGui_CloseChildPID") ;read the console, while the child window exists (and the console window is visible) While ProcessExists($pidChild) $ConsoleRead = StdoutRead($pidChild) If $ConsoleRead then $text = StringLeft(ControlGetText($hWnd,"",$hEditBox),65535) If $Logfile Then FileWrite($Logfile,$ConsoleRead) $text &= $ConsoleRead ControlSetText($hWnd,"",$hEditBox,$text) ConsoleWrite($ConsoleRead) ;scroll to bottom of console edit window _GUICtrlEdit_SetSel($hEditBox, 65535, 65535) endif Sleep(250) WEnd exit endif EndFunc Func EnableConsoleGui_CloseChildPID() ;if this func isn't used ;when you close the console gui ;the child "clone" of your script will keep running ProcessClose($pidChild) EndFunc
×
×
  • Create New...