mirror of
https://github.com/MontFerret/ferret.git
synced 2025-11-06 08:39:09 +02:00
Fixes (#193)
This commit is contained in:
@@ -50,6 +50,14 @@ const (
|
|||||||
ScreenshotFormatJPEG ScreenshotFormat = "jpeg"
|
ScreenshotFormatJPEG ScreenshotFormat = "jpeg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func handleLoadError(logger *zerolog.Logger, client *cdp.Client) {
|
||||||
|
err := client.Page.Close(context.Background())
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logger.Warn().Timestamp().Err(err).Msg("unabled to close document on load error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func IsScreenshotFormatValid(format string) bool {
|
func IsScreenshotFormatValid(format string) bool {
|
||||||
value := ScreenshotFormat(format)
|
value := ScreenshotFormat(format)
|
||||||
|
|
||||||
@@ -62,6 +70,8 @@ func LoadHTMLDocument(
|
|||||||
client *cdp.Client,
|
client *cdp.Client,
|
||||||
url string,
|
url string,
|
||||||
) (*HTMLDocument, error) {
|
) (*HTMLDocument, error) {
|
||||||
|
logger := logging.FromContext(ctx)
|
||||||
|
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
return nil, core.Error(core.ErrMissedArgument, "connection")
|
return nil, core.Error(core.ErrMissedArgument, "connection")
|
||||||
}
|
}
|
||||||
@@ -76,6 +86,8 @@ func LoadHTMLDocument(
|
|||||||
err = waitForLoadEvent(ctx, client)
|
err = waitForLoadEvent(ctx, client)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
handleLoadError(logger, client)
|
||||||
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,17 +95,17 @@ func LoadHTMLDocument(
|
|||||||
node, err := getRootElement(ctx, client)
|
node, err := getRootElement(ctx, client)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
handleLoadError(logger, client)
|
||||||
return nil, errors.Wrap(err, "failed to get root element")
|
return nil, errors.Wrap(err, "failed to get root element")
|
||||||
}
|
}
|
||||||
|
|
||||||
broker, err := createEventBroker(client)
|
broker, err := createEventBroker(client)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
handleLoadError(logger, client)
|
||||||
return nil, errors.Wrap(err, "failed to create event events")
|
return nil, errors.Wrap(err, "failed to create event events")
|
||||||
}
|
}
|
||||||
|
|
||||||
logger := logging.FromContext(ctx)
|
|
||||||
|
|
||||||
rootElement, err := LoadElement(
|
rootElement, err := LoadElement(
|
||||||
ctx,
|
ctx,
|
||||||
logger,
|
logger,
|
||||||
@@ -104,6 +116,10 @@ func LoadHTMLDocument(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
broker.Stop()
|
||||||
|
broker.Close()
|
||||||
|
handleLoadError(logger, client)
|
||||||
|
|
||||||
return nil, errors.Wrap(err, "failed to load root element")
|
return nil, errors.Wrap(err, "failed to load root element")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -129,6 +129,10 @@ func (drv *Driver) GetDocument(ctx context.Context, targetURL values.String) (va
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return LoadHTMLDocument(ctx, conn, client, url)
|
return LoadHTMLDocument(ctx, conn, client, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user