diff --git a/pkg/drivers/http/driver.go b/pkg/drivers/http/driver.go index 805731d8..37c1a691 100644 --- a/pkg/drivers/http/driver.go +++ b/pkg/drivers/http/driver.go @@ -137,7 +137,7 @@ func (drv *Driver) Open(ctx context.Context, params drivers.Params) (drivers.HTM Headers: drivers.NewHTTPHeadersWith(resp.Header), } - return NewHTMLPage(doc, params.URL, r, cookies) + return NewHTMLPage(doc, params.URL, r, cookies, drv) } func (drv *Driver) Parse(_ context.Context, params drivers.ParseParams) (drivers.HTMLPage, error) { @@ -149,7 +149,7 @@ func (drv *Driver) Parse(_ context.Context, params drivers.ParseParams) (drivers return nil, errors.Wrap(err, "failed to parse a document") } - return NewHTMLPage(doc, "#blank", drivers.HTTPResponse{}, nil) + return NewHTMLPage(doc, "#blank", drivers.HTTPResponse{}, nil, drv) } func (drv *Driver) Close() error { diff --git a/pkg/drivers/http/page.go b/pkg/drivers/http/page.go index d3a93ce7..65f83337 100644 --- a/pkg/drivers/http/page.go +++ b/pkg/drivers/http/page.go @@ -2,9 +2,10 @@ package http import ( "context" - "github.com/MontFerret/ferret/pkg/runtime/events" "hash/fnv" + "github.com/MontFerret/ferret/pkg/runtime/events" + "github.com/PuerkitoBio/goquery" "github.com/MontFerret/ferret/pkg/drivers" @@ -14,6 +15,7 @@ import ( ) type HTMLPage struct { + driver *Driver document *HTMLDocument cookies *drivers.HTTPCookies frames *values.Array @@ -25,6 +27,7 @@ func NewHTMLPage( url string, response drivers.HTTPResponse, cookies *drivers.HTTPCookies, + driver *Driver, ) (*HTMLPage, error) { doc, err := NewRootHTMLDocument(qdoc, url) @@ -37,6 +40,7 @@ func NewHTMLPage( p.cookies = cookies p.frames = nil p.response = response + p.driver = driver return p, nil } @@ -96,6 +100,7 @@ func (p *HTMLPage) Copy() core.Value { p.document.GetURL().String(), p.response, cookies, + p.driver, ) if err != nil { @@ -211,8 +216,22 @@ func (p *HTMLPage) WaitForFrameNavigation(_ context.Context, _ drivers.HTMLDocum return core.ErrNotSupported } -func (p *HTMLPage) Navigate(_ context.Context, _ values.String) error { - return core.ErrNotSupported +func (p *HTMLPage) Navigate(ctx context.Context, url values.String) error { + page, err := p.driver.Open(ctx, drivers.Params{ + URL: url.String(), + }) + if err != nil { + return err + } + + pp := page.(*HTMLPage) + + p.document = pp.document + p.cookies = pp.cookies + p.frames = pp.frames + p.response = pp.response + + return nil } func (p *HTMLPage) NavigateBack(_ context.Context, _ values.Int) (values.Boolean, error) {