page

package
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2023 License: MIT Imports: 18 Imported by: 1

Documentation

Overview

Commands for inspecting and manipulating the current DOM document and browser viewport.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Commands

type Commands struct {
	friendscript.Module
	// contains filtered or unexported fields
}

func New

func New(browser *browser.Browser, scopeable utils.Runtime) *Commands

func (*Commands) ClearIntercepts

func (self *Commands) ClearIntercepts() error

Clear all request intercepts.

func (*Commands) Intercept

func (self *Commands) Intercept(match string, args *InterceptArgs) error

Intercept all requests where the requested URL matches *match*, and modify the request according to the provided arguments.

func (*Commands) Pdf

func (self *Commands) Pdf(destination interface{}, args *PdfArgs) error

Render the current page as a PDF document, writing it to the given filename or writable destination object.

func (*Commands) Remove

func (self *Commands) Remove(selector dom.Selector, args *RemoveArgs) (int, error)

Remove all occurrences of the element(s) matching the given selector.

func (*Commands) Screenshot

func (self *Commands) Screenshot(destination interface{}, args *ScreenshotArgs) (*ScreenshotResponse, error)

Render the current page as a PNG or JPEG image, writing it to the given filename or writable destination object.

If the filename is the string `"temporary"`, a file will be created in the system's temporary area (e.g.: `/tmp`) and the screenshot will be written there. It is the caller's responsibility to remove the temporary file if desired. The temporary file path is available in the return object's `path` parameter.

func (*Commands) Source

func (self *Commands) Source(selector dom.Selector) (string, error)

Return the source for the given element, or for the whole page.

func (*Commands) Text

func (self *Commands) Text(selector dom.Selector) (string, error)

Return the text content for the given element, or for the whole page.

type InterceptArgs

type InterceptArgs struct {
	// Rewrite the response body with the provided string or with the contents of
	// an io.Reader.
	Body interface{} `json:"body"`

	// Read the response body contents from the named file.
	File string `json:"file"`

	// Specify that the interception should wait for response headers to be sent.  Otherwise the
	// request is intercepted prior to making the request.
	WaitForHeaders bool `json:"wait_for_headers"`

	// Should the request be aborted/rejected.
	Reject bool `json:"reject"`

	// Rewrite the request method to this.
	Method string `json:"method"`

	// Rewrite the request URL to this value.
	URL string `json:"url"`

	// Set the request headers.  Not valid is WaitForHeaders is set.
	Headers map[string]interface{} `json:"headers"`

	// Update the POST data to these values.
	PostData map[string]interface{} `json:"post_data"`

	// Only apply to response HTTP status codes in this list.
	Statuses []int `json:"statuses"`

	// Send credentials in response to this realm.  If empty, the provided credentials
	// will be sent to any authentication challenge.
	Realm string `json:"realm"`

	// Username to authenticate with.
	Username string `json:"username"`

	// Password to authenticate with.
	Password string `json:"password"`

	// Specify whether the intercept should persist after the first match.
	Persistent bool `json:"persistent"`
}

type PdfArgs

type PdfArgs struct {
	// Whether the given destination should be automatically closed for writing after the
	// PDF is written.
	Autoclose bool `json:"autoclose" default:"true"`
}

type RemoveArgs

type RemoveArgs struct {
	Parent dom.Selector `json:"parent"`
}

type ScreenshotArgs

type ScreenshotArgs struct {
	// If specified, the screenshot will attempt to capture just the matching element.
	Selector dom.Selector `json:"selector,omitempty"`

	// Determines how to handle multiple elements that are matched by Selector.
	// May be "tallest" or "first".
	Use string `json:"use,omitempty" default:"tallest"`

	Width  int `json:"width"`
	Height int `json:"height"`
	X      int `json:"x" default:"-1"`
	Y      int `json:"y" default:"-1"`

	// The output image format of the screenshot.  May be "png" or "jpeg".
	Format string `json:"format" default:"png"`

	// The quality of the image used during encoding.  Only applies to "jpeg" format.
	Quality int `json:"quality"`

	// Whether the given destination should be automatically closed for writing after the
	// screenshot is written.
	Autoclose bool `json:"autoclose" default:"true"`

	// Automatically resize the screen to the width and height.
	Autoresize bool `json:"autoresize" default:"true"`
}

type ScreenshotResponse

type ScreenshotResponse struct {
	// Details about the element that matched the given selector (if any).
	Element *dom.Element `json:"element,omitempty"`

	// The width of the screenshot (in pixels).
	Width int `json:"width"`

	// The height of the screenshot (in pixels).
	Height int `json:"height"`

	// The X position (relative to the viewport) the screenshot was taken at.
	X int `json:"x"`

	// The Y position (relative to the viewport) the screenshot was taken at.
	Y int `json:"y"`

	// The filesystem path that the screenshot was written to.
	Path string `json:"path,omitempty"`

	// The size of the screenshot (in bytes).
	Size int64 `json:"size,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL