in reply to Executing JavaScript function using WWW::Mechanize::Firefox

Try this  ....eval_in_page( $js ); where
my $js = <<'__JS__'; (function(){ function myFunction() { alert("Hello World!"); } myFunction(); })(); __JS__

Replies are listed 'Best First'.
Re^2: Executing JavaScript function using WWW::Mechanize::Firefox
by Anonymous Monk on Feb 17, 2016 at 02:18 UTC

    Thanks, but that yields the error "MozRepl::RemoteObject: TypeError: 'alert' called on an object that does not implement interface Window. at test_js.pl line 23."

    Also, my problem is that in my use case, I don't write the JavaScript myself -- I am trying to have Firefox use a website that has a couple of functions which I want to call.

      Thanks, but that yields the error "MozRepl::RemoteObject: TypeError: 'alert' called on an object that does not implement interface Window. at test_js.pl line 23."

      That is an important message and clue about the environment you're facing

      Also, my problem is that in my use case, I don't write the JavaScript myself -- I am trying to have Firefox use a website that has a couple of functions which I want to call.

      Can you get firefox to do that without involving perl ?

      Because browsers kind of go out of their way to forbid such tricks because of security issues

        Not sure I understand what kind of a clue this is. Can you elaborate?

        Manual operation of the website works just fine! And since ReplMoz is inside the browser, I should not be caught by the browser doing anything fishy, right?

        Here is what the actual link in the website I am facing looks like:

        <a href='#' onclick='goToPage(2);return false;'>Next &gt;</a>

        And yes, I know, I can click that link in a different way, but the thing is that I want to be able to tell it to which page it should go, i.e. I want to call goToPage with a parameter of my choosing.