In theory, the (Javascript) code that I use in WWW::Mechanize::FireFox::eval_in_page can redefine all functions:
sub eval_in_page { my ($self,$str) = @_; my $eval_in_sandbox = $self->repl->declare(<<'JS'); function (w,str,myalert) { var unsafeWin = w.wrappedJSObject; var safeWin = XPCNativeWrapper(unsafeWin); var sandbox = Components.utils.Sandbox(safeWin); sandbox.window = safeWin; sandbox.window.alert = myalert; // <-- sandbox.alert = myalert; // <-- sandbox.document = sandbox.window.document; sandbox.__proto__ = unsafeWin; var res = Components.utils.evalInSandbox(str, sandbox); return [res,typeof(res)]; }; JS my $window = $self->tab->{linkedBrowser}->{contentWindow}; my $uri = $self->uri; return @{ $eval_in_sandbox->("$uri",$window,sub {print "Alert: @_" +}}; };
Note that the callbacks from MozRepl::RemoteObject are not blocking and not delivered in real time to you, so you can only capture the results of the alert() call but cannot take any action there in Perl. For taking an immediate action, you have to write some Javascript.
I plan a nicer interface for ->eval_in_page that allows you to (re)define properties of the window object, but as currently, WWW::Mechanize::FireFox is under heavy development, I can't promise any timeframe :).
In reply to Re^3: fetch HTML page, do javascript, read output from alert/msgbox
by Corion
in thread fetch HTML page, do javascript, read output from alert/msgbox
by TheFlyingCorpse
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |