1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-06-23 00:28:10 +02:00

Added support to open blank page

This commit is contained in:
Tim Voronov
2018-10-04 21:37:28 -04:00
parent 71ee1f3dfe
commit c650d28b29
7 changed files with 55 additions and 27 deletions

View File

@ -21,6 +21,8 @@ import (
"time"
)
const BlankPageUrl = "about:blank"
type HtmlDocument struct {
sync.Mutex
logger *zerolog.Logger
@ -78,10 +80,12 @@ func LoadHtmlDocument(
return nil, err
}
err = waitForLoadEvent(ctx, client)
if url != BlankPageUrl {
err = waitForLoadEvent(ctx, client)
if err != nil {
return nil, err
if err != nil {
return nil, err
}
}
root, innerHtml, err := getRootElement(client)
@ -637,6 +641,10 @@ func (doc *HtmlDocument) WaitForNavigation(timeout values.Int) error {
}
func (doc *HtmlDocument) Navigate(url values.String) error {
if url == "" {
url = BlankPageUrl
}
ctx := context.Background()
repl, err := doc.client.Page.Navigate(ctx, page.NewNavigateArgs(url.String()))
@ -648,5 +656,5 @@ func (doc *HtmlDocument) Navigate(url values.String) error {
return errors.New(*repl.ErrorText)
}
return waitForLoadEvent(ctx, doc.client)
return doc.WaitForNavigation(5000)
}

View File

@ -38,6 +38,10 @@ func (drv *Driver) GetDocument(ctx context.Context, url string) (values.HtmlNode
ctx, cancel := context.WithTimeout(ctx, DefaultTimeout)
defer cancel()
if url == "" {
url = BlankPageUrl
}
// Create a new target belonging to the browser context, similar
// to opening a new tab in an incognito window.
createTargetArgs := target.NewCreateTargetArgs(url).SetBrowserContextID(drv.contextID)

View File

@ -297,7 +297,7 @@ func (el *HtmlElement) GetChildNode(idx values.Int) core.Value {
func (el *HtmlElement) QuerySelector(selector values.String) core.Value {
if !el.IsConnected() {
return values.NewArray(0)
return values.None
}
ctx := context.Background()