sub eval_in_page_with_redefined_alert { my ($self,$str,$redefined_alert) = @_; 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,$redefined_alert ) }; };
and call it as
eval_in_page_with_redefined_alert($mech,$str, sub { print "Caught aler +t(): @_" });
If that doesn't work for you, something likely is wrong with my Javascript. You'll then have to look at the Mozilla FireFox Javascript documentation to figure out how things should be done instead.
In reply to Re^7: 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: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |