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.





Reply via email to