mirror of
https://github.com/MontFerret/ferret.git
synced 2025-03-19 21:28:32 +02:00
Added support to open blank page
This commit is contained in:
parent
71ee1f3dfe
commit
c650d28b29
9
Gopkg.lock
generated
9
Gopkg.lock
generated
@ -137,6 +137,14 @@
|
|||||||
revision = "a96e63847dc3c67d17befa69c303767e2f84e54f"
|
revision = "a96e63847dc3c67d17befa69c303767e2f84e54f"
|
||||||
version = "v2.1"
|
version = "v2.1"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
|
digest = "1:f7aa53146bf79462509d4ce136826ebbd64907e4679e1b04e62758da6b68e589"
|
||||||
|
name = "github.com/orcaman/concurrent-map"
|
||||||
|
packages = ["."]
|
||||||
|
pruneopts = "UT"
|
||||||
|
revision = "b28018939af9022337862b94a463abb18abb3e0e"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:40e195917a951a8bf867cd05de2a46aaf1806c50cf92eebf4c16f78cd196f747"
|
digest = "1:40e195917a951a8bf867cd05de2a46aaf1806c50cf92eebf4c16f78cd196f747"
|
||||||
name = "github.com/pkg/errors"
|
name = "github.com/pkg/errors"
|
||||||
@ -228,6 +236,7 @@
|
|||||||
"github.com/mafredri/cdp/rpcc",
|
"github.com/mafredri/cdp/rpcc",
|
||||||
"github.com/mafredri/cdp/session",
|
"github.com/mafredri/cdp/session",
|
||||||
"github.com/natefinch/lumberjack",
|
"github.com/natefinch/lumberjack",
|
||||||
|
"github.com/orcaman/concurrent-map",
|
||||||
"github.com/pkg/errors",
|
"github.com/pkg/errors",
|
||||||
"github.com/rs/zerolog",
|
"github.com/rs/zerolog",
|
||||||
"github.com/sethgrid/pester",
|
"github.com/sethgrid/pester",
|
||||||
|
3
docs/examples/blank-page.fql
Normal file
3
docs/examples/blank-page.fql
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
LET doc = DOCUMENT("about:blank", true)
|
||||||
|
NAVIGATE(doc, "https://www.google.com/")
|
||||||
|
RETURN doc.url
|
@ -1,13 +1,12 @@
|
|||||||
LET doc = DOCUMENT("https://github.com/", true)
|
LET doc = DOCUMENT("https://github.com/", true)
|
||||||
|
|
||||||
LET main = ELEMENT(doc, '.application-main')
|
LET main = ELEMENT(doc, '.application-main')
|
||||||
LOG('innerText:start')
|
|
||||||
LET mainTxt = main.innerText
|
LET mainTxt = main.innerText
|
||||||
LOG('innerText:end')
|
|
||||||
|
|
||||||
NAVIGATE(doc, "https://github.com/features")
|
NAVIGATE(doc, "https://github.com/features")
|
||||||
|
|
||||||
LET features = ELEMENT(doc, '.application-main')
|
LET features = ELEMENT(doc, '.application-main')
|
||||||
LET featuresTxt = features.innerText
|
LET featuresTxt = features.innerText
|
||||||
|
|
||||||
|
LOG("featuresTxt:", featuresTxt)
|
||||||
|
|
||||||
RETURN mainTxt == featuresTxt
|
RETURN mainTxt == featuresTxt
|
||||||
|
@ -1775,23 +1775,28 @@ func TestParam(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHtml(t *testing.T) {
|
func TestHtml(t *testing.T) {
|
||||||
// Convey("Should load a document", t, func() {
|
Convey("Should load a document", t, func() {
|
||||||
// c := compiler.New()
|
c := compiler.New()
|
||||||
//
|
|
||||||
// out, err := c.MustCompile(`
|
out, err := c.MustCompile(`
|
||||||
//LET doc = DOCUMENT("https://github.com/", true)
|
LET doc = DOCUMENT("https://github.com/", true)
|
||||||
//LET btn = ELEMENT(doc, ".HeaderMenu a")
|
LET main = ELEMENT(doc, '.application-main')
|
||||||
//
|
LET mainTxt = main.innerText
|
||||||
//CLICK(btn)
|
|
||||||
//WAIT_NAVIGATION(doc)
|
NAVIGATE(doc, "https://github.com/features")
|
||||||
//WAIT_ELEMENT(doc, '.IconNav')
|
|
||||||
//
|
LET features = ELEMENT(doc, '.application-main')
|
||||||
//RETURN INNER_HTML_ALL(doc, '.IconNav a')
|
LET featuresTxt = features.innerText
|
||||||
//
|
|
||||||
// `).Run(context.Background())
|
LOG("featuresTxt:", featuresTxt)
|
||||||
//
|
|
||||||
// So(err, ShouldBeNil)
|
RETURN mainTxt == featuresTxt
|
||||||
//
|
|
||||||
// So(string(out), ShouldEqual, `"int"`)
|
|
||||||
// })
|
`).Run(context.Background())
|
||||||
|
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
So(string(out), ShouldEqual, `"int"`)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const BlankPageUrl = "about:blank"
|
||||||
|
|
||||||
type HtmlDocument struct {
|
type HtmlDocument struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
logger *zerolog.Logger
|
logger *zerolog.Logger
|
||||||
@ -78,10 +80,12 @@ func LoadHtmlDocument(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = waitForLoadEvent(ctx, client)
|
if url != BlankPageUrl {
|
||||||
|
err = waitForLoadEvent(ctx, client)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
root, innerHtml, err := getRootElement(client)
|
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 {
|
func (doc *HtmlDocument) Navigate(url values.String) error {
|
||||||
|
if url == "" {
|
||||||
|
url = BlankPageUrl
|
||||||
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
repl, err := doc.client.Page.Navigate(ctx, page.NewNavigateArgs(url.String()))
|
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 errors.New(*repl.ErrorText)
|
||||||
}
|
}
|
||||||
|
|
||||||
return waitForLoadEvent(ctx, doc.client)
|
return doc.WaitForNavigation(5000)
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,10 @@ func (drv *Driver) GetDocument(ctx context.Context, url string) (values.HtmlNode
|
|||||||
ctx, cancel := context.WithTimeout(ctx, DefaultTimeout)
|
ctx, cancel := context.WithTimeout(ctx, DefaultTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
if url == "" {
|
||||||
|
url = BlankPageUrl
|
||||||
|
}
|
||||||
|
|
||||||
// Create a new target belonging to the browser context, similar
|
// Create a new target belonging to the browser context, similar
|
||||||
// to opening a new tab in an incognito window.
|
// to opening a new tab in an incognito window.
|
||||||
createTargetArgs := target.NewCreateTargetArgs(url).SetBrowserContextID(drv.contextID)
|
createTargetArgs := target.NewCreateTargetArgs(url).SetBrowserContextID(drv.contextID)
|
||||||
|
@ -297,7 +297,7 @@ func (el *HtmlElement) GetChildNode(idx values.Int) core.Value {
|
|||||||
|
|
||||||
func (el *HtmlElement) QuerySelector(selector values.String) core.Value {
|
func (el *HtmlElement) QuerySelector(selector values.String) core.Value {
|
||||||
if !el.IsConnected() {
|
if !el.IsConnected() {
|
||||||
return values.NewArray(0)
|
return values.None
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user