Inject Javascript into Chrome

Post your working scripts, libraries and tools
sancarn
Posts: 188
Joined: 01 Mar 2016, 14:52

Inject Javascript into Chrome

09 Oct 2017, 12:24

I recognize this is relatively simple but it could be useful to some:

Github repository.

Sadly it isn't perfect still as it appears as though I can't figure out how to execute the code through IAccessible. Ultimately that means I can inject the code but I can't run it without entering chrome and sending {F6}{enter} :facepalm:

Regardless, for those who can't install plugins it looks like the best method there is as far as I can see. Also, sadly it doesn't look like there is a 2-way link... So you can send data to chrome, but unless you enable accessibility in chrome://accessibility you won't be able to get any data out unless you use alert(data) however here you can only have around 1600 bytes of data. Sooo yeah.

Anyway I hope some people find this useful :)
User avatar
Delta Pythagorean
Posts: 237
Joined: 13 Feb 2017, 13:44
Location: Equestria

Re: Inject Javascript into Chrome

11 Oct 2017, 19:57

As of right now, I'm working on a Chrome WebAPI to talk to and communicate with websites via Chrome, the problem is I haven't been able to do anything with it lol
As of right now, it's basically a toddler. You can visit the GitHub page in my signature below this message :D
A_AhkUser
Posts: 491
Joined: 06 Mar 2017, 16:18
Location: France

Re: Inject Javascript into Chrome

13 Oct 2017, 19:42

Hi Sancarn,

Actually I didn't know one can reliably operate upon chrome search bar. Thanks for sharing. It's too bad, however, that it requires such a huge library like acc. For that matter, and as for me - Windows 8.1; chrome up-to-date - injectJS func, most of time, fails to send Enter key in particular and in such a way that I must manually press enter in order to inject the js source.

Btw, here's a example of speech recognition feature by a hacky 2-way link using injectJS and without using any plugin: chrome send the speech recognition result or its recognition state to ahk by its title (retrieved by WInGetTitle) which is set by the injected js, js triggered by WinMove (the javascript also previously set onresize-eventlisteners).

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Video Game Reader
Image
github
demo
sancarn
Posts: 188
Joined: 01 Mar 2016, 14:52

Re: Inject Javascript into Chrome

14 Oct 2017, 09:48

A_AhkUser wrote:Actually I didn't know one can reliably operate upon chrome search bar. Thanks for sharing. It's too bad, however, that it requires such a huge library like acc. For that matter, and as for me - Windows 8.1; chrome up-to-date - injectJS func, most of time, fails to send Enter key in particular and in such a way that I must manually press enter in order to inject the js source.


Well of course it doesn't require the whole of acc.ahk I was just too lazy to separate the functions I needed... :P Even more so, it's my custom version of acc.ahk which is even bigger... Really it only needs Acc_Parent, Acc_Child, Acc_GetChild and Acc_ObjectFromWindow.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



I think the above code should work out... However in general when working on a project I'll keep all the libraries I can. But I guess that's the difference between a major and minor projects :P I can see why on a minor project you'd want cut down code :) Also to be fair a lot of the whitespace in the acc code could be cut down. It'd be kinda cool to have an ahk version of minify :D

Btw, here's a example of speech recognition feature by a hacky 2-way link using injectJS and without using any plugin: chrome send the speech recognition result or its recognition state to ahk by its title (retrieved by WInGetTitle) which is set by the injected js, js triggered by WinMove (the javascript also previously set onresize-eventlisteners).


Damn that's cool :D Thanks for sharing :D

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 12 guests