Skip to content
This repository has been archived by the owner on Aug 19, 2021. It is now read-only.

Execute javascript in current web page context #48

Closed
nisaacson opened this issue Oct 9, 2013 · 1 comment
Closed

Execute javascript in current web page context #48

nisaacson opened this issue Oct 9, 2013 · 1 comment

Comments

@nisaacson
Copy link

How would can I execute javascript in the currently loaded page via the repl?

# load https://example.com
repl> content.location.href = 'https://example.com'

# say that example.com exposes a global function called pageStatus(),
# how do I call that function and get the results back in the repl
repl> content.window.pageStatus() 
// returns !!! TypeError: content.window.pageStatus is not a function

Loading the page in firefox and using the developer tools console I can execute any of the following correctly

window.pageStatus()
content.pageStatus()
content.window.pageStatus()
pageStatus()
@nisaacson
Copy link
Author

It turns out I need to enter the content first via the repl

repl> repl.enter(content)
repl> window.pageStatus()
# correct output returned here
repl> repl.back() # exit out of content context

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant