in reply to Re^6: fetch HTML page, do javascript, read output from alert/msgbox
in thread fetch HTML page, do javascript, read output from alert/msgbox
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: fetch HTML page, do javascript, read output from alert/msgbox
by TheFlyingCorpse (Novice) on Nov 11, 2009 at 14:54 UTC | |
by Corion (Patriarch) on Nov 11, 2009 at 15:18 UTC | |
by TheFlyingCorpse (Novice) on Nov 11, 2009 at 16:45 UTC |