Sign in to follow this  
Followers 0
4Eyes

How to 'send' JavaScript to Chrome?

19 posts in this topic

Folks,

I dunno if the topic correctly describes what I'm trying to do which is simply get the url for the current tab in Chrome.

It appears that Javascript is required and I found that this code:

var currentURL = window.location;

alert(currentURL.href)

entered into the Chrome console will pop a MsgBox (or equiv). So now the question becomes how do I send it to Chrome?

I tried this:

ConsoleWrite("Make Chrome active..." & @CRLF)
Sleep(3000)

ConsoleWrite("you've got 3 seconds..." & @CRLF)
Sleep(3000)

Send("var currentURL = window.location; alert(currentURL.href)")

but it just goes to the address bar of an empty tab or flashes the screen, so it appears the idea is wrong.

I've scoured the forums for anything Java related and looked at FF.au3 but got lost in the __FFSend() stuff.

Is there a simple way to do this?

4Eyes

Share this post


Link to post
Share on other sites



AdmiralAlkex,

It's quite obvious that FF stands for FireFox, but as it uses Java I thought I might glean something from it, but no.

Sheesh!

4Eyes

Share this post


Link to post
Share on other sites

http://code.google.com/chrome/extensions/api_index.html

Chrome APIs. A single Google search away.

Share this post


Link to post
Share on other sites

AdmiralAlkex,

It's quite obvious that FF stands for FireFox, but as it uses Java I thought I might glean something from it, but no.

Sheesh!

4Eyes

You aren't even using Java, so yeah, that makes sense.

:x

Share this post


Link to post
Share on other sites

AdmiralAlkex,

I think maybe the English is getting confused here. I looked into FF.au3 as it packages Java (I believe) to talk to FireFox. It appears that Chrome also can be manipulated via Java hence I looked into FF.au3 to try to understand how to do it. Your statement "You aren't even using Java, so yeah, that makes sense." ... does not make sense. Let's just drop it if you have nothing useful to add.

Richard Robertson,

Yeah sure, 1 search found a reference to API's for Chrome, but again, that's not related to the subject of this thread but is thinking along different lines. I've looked at the doc there but I hardly understand a word. It uses JSON which is adding another layer to my problem as I don't do JSON, let alone Javascript.

My original question remains. Can anybody please offer some advice that I can understand?

4Eyes

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

That is the subject of the thread. You want to automate Chrome. Google provided an API to do so with.

This is a support forum, not a "write my code" or "rent a coder" forum.

Edited by Richard Robertson

Share this post


Link to post
Share on other sites

Jeez Louise! I did not ask for anybody to write any code for me and I find your words quite rude. That is something that is becoming so common in these forums, and something that I need to stop also.

Actually, the subject of the script is not 'How do I automate chrome?' at all. You've read between the lines and suggested an alternative which I can't make head nor tail of, thereof of no use to me. If you don't care to either help with the initial subject or give me a clue as to how to use the API then your comments don't help at all.

Share this post


Link to post
Share on other sites

You are trying to send some Javascript to the Chrome engine that is not part of the web page being viewed. You're not doing it by hand. That makes it automation.

AdmiralAlkex is right in what he said. Using the Firefox UDF will net you nothing when trying to work with Chrome. On a related note, yes, Java and Javascript are not related.

To get the address of the web page being displayed in Chrome would require you to have knowledge of the open tabs, which are in turn, separate processes. If you aren't using the Chrome API, which is designed for non-Google code to interact with the browser, you're not going to get anywhere.

Call me rude if you like. It doesn't bother me in the least.

Share this post


Link to post
Share on other sites

If that's automation then I didn't see it that way. I still don't understand, but anyway.

I didn't try to use nor was I implying I'd like to use FF.au3 to talk to Chrome.

Can you shed some light on how I use the API? I don't understand how to open it, send commands or anything else so any scrap would be a help.

4Eyes

Share this post


Link to post
Share on other sites

Here's a silly question, why not just use IE.au3 or FF.au3 that is already provided?

I only ask, because I know that IE.au3 has extensive documentation and I'm aware there's a thread for FF.au3.

What possible reason do you have to re-invent the wheel on something that would ultimately lead to many many more hours of yours and others time than probably is necessary?


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

SmOke_N,

Well, I appreciate your reply, but it's as I said in the first line of my first post. I wish to read the url from Chrome in particular, not IE or FF.

I'm not trying to waste anybody's time, including my own. As often happens here, a question leads to an answer from somebody who has already toyed with, poked at or experimented with various techniques to achieve an end. I was hoping that may be the case again.

4Eyes

Share this post


Link to post
Share on other sites

I'm not trying to waste anybody's time, including my own. As often happens here, a question leads to an answer from somebody who has already toyed with, poked at or experimented with various techniques to achieve an end. I was hoping that may be the case again.

A recursive FileListToArray maybe. Browser udf's doesn't tend to just happen by themselves.

:x

Share this post


Link to post
Share on other sites

AdmiralAlkex,

Thanks for your reply, but I can't imagine what files would represent the current page viewed in Chrome. I'm aware of the cache, but that's nothing like realtime either.

4Eyes

Share this post


Link to post
Share on other sites

SmOke_N,

Well, I appreciate your reply, but it's as I said in the first line of my first post. I wish to read the url from Chrome in particular, not IE or FF.

I'm not trying to waste anybody's time, including my own. As often happens here, a question leads to an answer from somebody who has already toyed with, poked at or experimented with various techniques to achieve an end. I was hoping that may be the case again.

4Eyes

As I'm sure you're frustrated a bit, have no idea what to do or how to do it, you still haven't answered my question as to why chrome and not the others.

Putting that aside, I'd suggest, if you don't understand how to use API's, and have found nothing in autoit ( forum posts ) that does what you desire, to maybe look at outside alternatives.

Maybe you can break down what they've done and translate it over?

Here's a start: http://www.google.com/search?q=automate+chrome

Not sure what WaitN is, but I saw it in a few of those, maybe that could lead you in the right direction.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

AdmiralAlkex,

If that's not what you meant then I have no idea what you are referring to.

Share this post


Link to post
Share on other sites

SmOke_N,

Yep, I'm quite frustrated. In fact, quite doesn't actually touch the sides.

I would expect to interact with a DLL but I see few if any references to this. In fact I think this quote from http://answers.yahoo.com/question/index?qid=20100120115218AAS9jEv sums it up quite well:

"Anyone know anything about programming Chrome automated scripts? Tell us how to get started working with it? Google makes several references to it but its really obscured by clueless Chromium developer lingo andthey seem to be assuming everyone wants to become a developer and work with beta versions and all I want to do is have a browser that supports some basic scripting". I agree!

I had a look at which looks to be an excellent intro into interacting with DLL's and

which is the eBay udf with quite a different take on things.

I made a little progress from the Javascript point of view with this: http://www.google.co.uk/support/forum/p/Chrome/thread?tid=01a7b247949e2b11&hl=en

BTW, WatiN stands for "Web Application Testing In .Net" so while it has certain abilities, they are hidden unlike say translating something from VBS or VB 6.

Also tried ripdad's idea of ctrl-l/ctrl-c etc but it REALLY carries on with Chrome. Goes ga-ga when trying to enter a new URL. I've tried a few things like getting the existing clipboard and restoring it but that's not working well either.

I've started looking at the cache_1 etc files but they get big really fast. I dare say I could extract url's but I want dates visited too so that will involve a lot of work, but I'm really compulsive and don't give up easily.

As you can see I've tried lotsa stuff and have researched hard. So, 'frustrated' is hardly the word.

Again, thanks for taking the time to offer some suggestions.

Regards,

4Eyes

Share this post


Link to post
Share on other sites

Bumping once only in case there are some fresh eyes out there.

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
Sign in to follow this  
Followers 0