Re: JavaScript/Perl Question
Thanks for the code Philippe. I'm going to try it. I think it'd be cool if the proxy automatically ran the validator on the page being proxied and the javascript that was added to the page by the proxy would write the results to a logger window or alert. Is this an easy thing to do with HTTP::Proxy? The other thing I would look at is a 'bookmarklet' (browser bookmark with javascript: url) which seems to be able to get at the source for a page. -Kevin Philippe 'BooK' Bruhat wrote: Le jeudi 29 janvier 2004 à 07:22, Ovid écrivait: --- Tony Bowden [EMAIL PROTECTED] wrote: On Tue, Jan 27, 2004 at 10:37:48AM -0500, Potozniak, Andrew wrote: To make a long story short I can not get access to the source of the bottom frame through JavaScript because of an access denied error. This is a security feature in most browsers - Andrew, Hate to say it, but Tony's right. I've run into this before and the problem is not insurmountable, but it means that you have to have your app running on a server. Or that you need a proxy that'll modify the page on the fly (by adding the javascript you need). My pet module HTTP::Proxy (available on CPAN) can help you do this. :-) I suppose you mostly need a filter that'll add the necessary code to load the javascript somewhere near the opening body tag of each and every text/html response. The code of such a proxy is as simple as: use HTTP::Proxy; use HTML::Parser; use HTTP::Proxy::BodyFilter::htmlparser; # define the filter (the most difficult part) # filters not using HTML::Parser are much simpler my $parser = HTML::Parser-new( api_version = 3 ); $parser-handler( start = sub { my ( $self, $tag, $text ) = @_; $self-{output} .= $text; $self-{output} .= YOUR JAVASCRIPT HERE if $tag eq 'body'; }, self,tagname,text ); $parser-handler( default = sub { my ($self, $text) = @_; $self-{output} .= $text; }, self,text ); # this is a read-write filter (rw = 1) # that is the reason why we had to copy everything into $self-{output} my $filter = HTTP::Proxy::BodyFilter::htmlparser-new( $parser, rw = 1 ); # create and launch the proxy my $proxy = HTTP::Proxy-new(); $proxy-logmask( 1 ); # terse logs $proxy-push_filter( response = $filter, mime = 'text/html', host = 'www.example.com' ); $proxy-start(); And now you have all the javascript you need added to the HTML pages you want. There is also a 'path' parameter to the push_filter() method, you you want to add the javascript only to parts of the web site. Note: I'm not very proud of the way I plugged HTML::Parser objects into HTTP::Proxy. But HTML::Parser uses callbacks, just as HTTP::Proxy (LWP::UA, actually) does. If anybody has better ideas, I all ears.
Re: JavaScript/Perl Question
Le jeudi 29 janvier 2004 à 07:22, Ovid écrivait: --- Tony Bowden [EMAIL PROTECTED] wrote: On Tue, Jan 27, 2004 at 10:37:48AM -0500, Potozniak, Andrew wrote: To make a long story short I can not get access to the source of the bottom frame through JavaScript because of an access denied error. This is a security feature in most browsers - Andrew, Hate to say it, but Tony's right. I've run into this before and the problem is not insurmountable, but it means that you have to have your app running on a server. Or that you need a proxy that'll modify the page on the fly (by adding the javascript you need). My pet module HTTP::Proxy (available on CPAN) can help you do this. :-) I suppose you mostly need a filter that'll add the necessary code to load the javascript somewhere near the opening body tag of each and every text/html response. The code of such a proxy is as simple as: use HTTP::Proxy; use HTML::Parser; use HTTP::Proxy::BodyFilter::htmlparser; # define the filter (the most difficult part) # filters not using HTML::Parser are much simpler my $parser = HTML::Parser-new( api_version = 3 ); $parser-handler( start = sub { my ( $self, $tag, $text ) = @_; $self-{output} .= $text; $self-{output} .= YOUR JAVASCRIPT HERE if $tag eq 'body'; }, self,tagname,text ); $parser-handler( default = sub { my ($self, $text) = @_; $self-{output} .= $text; }, self,text ); # this is a read-write filter (rw = 1) # that is the reason why we had to copy everything into $self-{output} my $filter = HTTP::Proxy::BodyFilter::htmlparser-new( $parser, rw = 1 ); # create and launch the proxy my $proxy = HTTP::Proxy-new(); $proxy-logmask( 1 ); # terse logs $proxy-push_filter( response = $filter, mime = 'text/html', host = 'www.example.com' ); $proxy-start(); And now you have all the javascript you need added to the HTML pages you want. There is also a 'path' parameter to the push_filter() method, you you want to add the javascript only to parts of the web site. Note: I'm not very proud of the way I plugged HTML::Parser objects into HTTP::Proxy. But HTML::Parser uses callbacks, just as HTTP::Proxy (LWP::UA, actually) does. If anybody has better ideas, I all ears. -- Philippe BooK Bruhat Your reputation is what you make of it... and what you choose to take with you. (Moral from Groo The Wanderer #48 (Epic))
Re: JavaScript/Perl Question
On Tue, Jan 27, 2004 at 10:37:48AM -0500, Potozniak, Andrew wrote: To make a long story short I can not get access to the source of the bottom frame through JavaScript because of an access denied error. Has anyone else ran into this problem or does anyone know of a solution to this problem? This is a security feature in most browsers - you should generally not be allowed to mess with other people's sites. There's no good workaround that I know. Tony
Re: JavaScript/Perl Question
Although it doesn't address the frame/Javascript issue, I believe this Mozilla plug-in solves the bigger problem of running various validators on a page sitting in the browser. http://checky.mozdev.org/ Although I must admit that I didn't test it because it appears they don't support Mac OS X. On Jan 27, 2004, at 10:37 AM, Potozniak, Andrew wrote: I have been trying in JavaScript and Perl to write a framed page to allow a user to click through a website and validate it as they wish using framework I built that uses to W3C's validation services. == Jim Brandt Administrative Computing Services University at Buffalo
JavaScript/Perl Question
I have been trying in JavaScript and Perl to write a framed page to allow a user to click through a website and validate it as they wish using framework I built that uses to W3C's validation services. So I have a top frame which is like the control panel (you can tell the bottom frame where to go and you can validate it if you wish) and a bottom frame which is the browser. To make a long story short I can not get access to the source of the bottom frame through JavaScript because of an access denied error. Has anyone else ran into this problem or does anyone know of a solution to this problem? Any help would be greatly appreciated. Thanks, ~~Andrew