Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Source of Current Tab in Google Chrome via Applescript

It's child's play to do this in Safari, which has good Applescript support. Google Chrome's AS support has just arrived so I'm giving them the benefit of the doubt. I am basically trying to grab the current HTML via the clipboard so I can get information out. We have some nifty commands like this:

tell application "Google Chrome"
 view source of active tab of window 1
 save active tab of window 1
 print active tab of window 1
 reload active tab of window 1
 go back active tab of window 1
 go forward active tab of window 1
 copy selection of active tab of window 1
 paste selection active tab of window 1
end tell

but alas you can't say "set X to source of active tab of window 1". Anyone have any suggestions for me? My current ideas are to load the code I need in the background in Safari (pretty ugly) or try to display source and grab it with UI script, but that's also ugly. Also I keep encountering scripting bugs that keep it from working.

Any help would be appreciated.

like image 879
Peter Payne Avatar asked Dec 14 '10 16:12

Peter Payne


1 Answers

Since google chrome supports Javascript

--Applescript code
tell active tab of window 1
    set sourcehtml to execute javascript
    document.getElementsByTagName('html')[0].innerHTML
end tell
like image 70
lemonteh Avatar answered Nov 02 '22 23:11

lemonteh