Documentation ¶
Index ¶
- Constants
- Variables
- type OpenWebPageSettings
- type PaperSize
- type PaperSizeMargin
- type Position
- type Process
- type Rect
- type Ref
- type WebPage
- func (p *WebPage) AddCookie(cookie *http.Cookie) (bool, error)
- func (p *WebPage) CanGoBack() (bool, error)
- func (p *WebPage) CanGoForward() (bool, error)
- func (p *WebPage) ClearCookies() error
- func (p *WebPage) ClipRect() (Rect, error)
- func (p *WebPage) Close() error
- func (p *WebPage) Content() (string, error)
- func (p *WebPage) Cookies() ([]*http.Cookie, error)
- func (p *WebPage) CustomHeaders() (http.Header, error)
- func (p *WebPage) DeleteCookie(name string) (bool, error)
- func (p *WebPage) Evaluate(script string) (interface{}, error)
- func (p *WebPage) EvaluateAsync(script string, delay time.Duration) error
- func (p *WebPage) EvaluateJavaScript(script string) (interface{}, error)
- func (p *WebPage) FocusedFrameName() (string, error)
- func (p *WebPage) FrameContent() (string, error)
- func (p *WebPage) FrameCount() (int, error)
- func (p *WebPage) FrameName() (string, error)
- func (p *WebPage) FrameNames() ([]string, error)
- func (p *WebPage) FramePlainText() (string, error)
- func (p *WebPage) FrameTitle() (string, error)
- func (p *WebPage) FrameURL() (string, error)
- func (p *WebPage) Go(index int) error
- func (p *WebPage) GoBack() error
- func (p *WebPage) GoForward() error
- func (p *WebPage) IncludeJS(url string) error
- func (p *WebPage) InjectJS(filename string) error
- func (p *WebPage) LibraryPath() (string, error)
- func (p *WebPage) NavigationLocked() (bool, error)
- func (p *WebPage) OfflineStoragePath() (string, error)
- func (p *WebPage) OfflineStorageQuota() (int, error)
- func (p *WebPage) Open(url string) error
- func (p *WebPage) OwnsPages() (bool, error)
- func (p *WebPage) Page(name string) (*WebPage, error)
- func (p *WebPage) PageWindowNames() ([]string, error)
- func (p *WebPage) Pages() ([]*WebPage, error)
- func (p *WebPage) PaperSize() (PaperSize, error)
- func (p *WebPage) PlainText() (string, error)
- func (p *WebPage) Reload() error
- func (p *WebPage) Render(filename, format string, quality int) error
- func (p *WebPage) RenderBase64(format string) (string, error)
- func (p *WebPage) ScrollPosition() (Position, error)
- func (p *WebPage) SendKeyboardEvent(eventType string, key string, modifier int) error
- func (p *WebPage) SendMouseEvent(eventType string, mouseX, mouseY int, button string) error
- func (p *WebPage) SetClipRect(rect Rect) error
- func (p *WebPage) SetContent(content string) error
- func (p *WebPage) SetContentAndURL(content, url string) error
- func (p *WebPage) SetCookies(cookies []*http.Cookie) error
- func (p *WebPage) SetCustomHeaders(header http.Header) error
- func (p *WebPage) SetFrameContent(content string) error
- func (p *WebPage) SetLibraryPath(path string) error
- func (p *WebPage) SetNavigationLocked(value bool) error
- func (p *WebPage) SetOwnsPages(v bool) error
- func (p *WebPage) SetPaperSize(size PaperSize) error
- func (p *WebPage) SetScrollPosition(pos Position) error
- func (p *WebPage) SetSettings(settings WebPageSettings) error
- func (p *WebPage) SetViewportSize(width, height int) error
- func (p *WebPage) SetZoomFactor(factor float64) error
- func (p *WebPage) Settings() (WebPageSettings, error)
- func (p *WebPage) Stop() error
- func (p *WebPage) SwitchToFocusedFrame() error
- func (p *WebPage) SwitchToFrameName(name string) error
- func (p *WebPage) SwitchToFramePosition(pos int) error
- func (p *WebPage) SwitchToMainFrame() error
- func (p *WebPage) SwitchToParentFrame() error
- func (p *WebPage) Title() (string, error)
- func (p *WebPage) URL() (string, error)
- func (p *WebPage) UploadFile(selector, filename string) error
- func (p *WebPage) ViewportSize() (width, height int, err error)
- func (p *WebPage) WindowName() (string, error)
- func (p *WebPage) ZoomFactor() (float64, error)
- type WebPageSettings
Constants ¶
const ( ShiftKey = 0x02000000 CtrlKey = 0x04000000 AltKey = 0x08000000 MetaKey = 0x10000000 Keypad = 0x20000000 )
Keyboard modifiers.
const ( DefaultPort = 20202 DefaultBinPath = "phantomjs" )
Default settings.
Variables ¶
var DefaultProcess = NewProcess()
DefaultProcess is a global, shared process. It must be opened before use.
var ( // ErrInjectionFailed is returned by InjectJS when injection fails. ErrInjectionFailed = errors.New("injection failed") )
Functions ¶
This section is empty.
Types ¶
type OpenWebPageSettings ¶
type OpenWebPageSettings struct {
Method string `json:"method"`
}
OpenWebPageSettings represents the settings object passed to WebPage.Open().
type PaperSize ¶
type PaperSize struct { // Dimensions of the paper. // This can also be specified via Format. Width string Height string // Supported formats: "A3", "A4", "A5", "Legal", "Letter", "Tabloid". Format string // Margins around the paper. Margin *PaperSizeMargin // Supported orientations: "portrait", "landscape". Orientation string }
PaperSize represents the size of a webpage when rendered as a PDF.
Units can be specified in "mm", "cm", "in", or "px". If no unit is specified then "px" is used.
type PaperSizeMargin ¶
PaperSizeMargin represents the margins around the paper.
type Process ¶
type Process struct { // Path to the 'phantomjs' binary. BinPath string // HTTP port used to communicate with phantomjs. Port int // Output from the process. Stdout io.Writer Stderr io.Writer // SSL Error messages are a pain in the ass IgnoreSslErrors bool // contains filtered or unexported fields }
Process represents a PhantomJS process.
func (*Process) CreateWebPage ¶
CreateWebPage returns a new instance of a "webpage".
type Ref ¶
type Ref struct {
// contains filtered or unexported fields
}
Ref represents a reference to an object in phantomjs.
type WebPage ¶
type WebPage struct {
// contains filtered or unexported fields
}
WebPage represents an object returned from "webpage.create()".
func CreateWebPage ¶
CreateWebPage returns a new instance of a "webpage" using the default process.
func (*WebPage) AddCookie ¶
AddCookie adds a cookie to the page. Returns true if the cookie was successfully added.
func (*WebPage) CanGoForward ¶
CanGoForward returns true if the page can be navigated forward.
func (*WebPage) ClearCookies ¶
ClearCookies deletes all cookies visible to the current URL.
func (*WebPage) ClipRect ¶
ClipRect returns the clipping rectangle used when rendering. Returns nil if no clipping rectangle is set.
func (*WebPage) CustomHeaders ¶
CustomHeaders returns a list of additional headers sent with the web page.
func (*WebPage) DeleteCookie ¶
DeleteCookie removes a cookie with a matching name. Returns true if the cookie was successfully deleted.
func (*WebPage) Evaluate ¶
Evaluate executes a JavaScript function in the context of the web page. Returns the value returned by the function.
func (*WebPage) EvaluateAsync ¶
EvaluateAsync executes a JavaScript function and returns immediately. Execution is delayed by delay. No value is returned.
func (*WebPage) EvaluateJavaScript ¶
EvaluateJavaScript executes a JavaScript function. Returns the value returned by the function.
func (*WebPage) FocusedFrameName ¶
FocusedFrameName returns the name of the currently focused frame.
func (*WebPage) FrameContent ¶
FrameContent returns the content of the current frame.
func (*WebPage) FrameCount ¶
FrameCount returns the total number of frames.
func (*WebPage) FrameNames ¶
FrameNames returns an list of frame names.
func (*WebPage) FramePlainText ¶
FramePlainText returns the plain text representation of the current frame content.
func (*WebPage) FrameTitle ¶
FrameTitle returns the title of the current frame.
func (*WebPage) Go ¶
Go navigates to the page in history by relative offset. A positive index moves forward, a negative index moves backwards.
func (*WebPage) IncludeJS ¶
IncludeJS includes an external script from url. Returns after the script has been loaded.
func (*WebPage) InjectJS ¶
InjectJS injects an external script from the local filesystem.
The script will be loaded from the Process.Path() directory. If it cannot be found then it is loaded from the library path.
func (*WebPage) LibraryPath ¶
LibraryPath returns the path used by InjectJS() to resolve scripts. Initially it is set to Process.Path().
func (*WebPage) NavigationLocked ¶
NavigationLocked returns true if the navigation away from the page is disabled.
func (*WebPage) OfflineStoragePath ¶
OfflineStoragePath returns the path used by offline storage.
func (*WebPage) OfflineStorageQuota ¶
OfflineStorageQuota returns the number of bytes that can be used for offline storage.
func (*WebPage) Page ¶
Page returns an owned page by window name. Returns nil if the page cannot be found.
func (*WebPage) PageWindowNames ¶
PageWindowNames returns an list of owned window names.
func (*WebPage) Render ¶
Render renders the web page to a file with the given format and quality settings. This supports the "PDF", "PNG", "JPEG", "BMP", "PPM", and "GIF" formats.
func (*WebPage) RenderBase64 ¶
RenderBase64 renders the web page to a base64 encoded string.
func (*WebPage) ScrollPosition ¶
ScrollPosition returns the current scroll position of the page.
func (*WebPage) SendKeyboardEvent ¶
SendKeyboardEvent sends a keyboard event as if it came from the user. It is not a synthetic event.
The eventType can be "keyup", "keypress", or "keydown".
The key argument is a string or a key listed here: https://github.com/ariya/phantomjs/commit/cab2635e66d74b7e665c44400b8b20a8f225153a
Keyboard modifiers can be joined together using the bitwise OR operator.
func (*WebPage) SendMouseEvent ¶
SendMouseEvent sends a mouse event as if it came from the user. It is not a synthetic event.
The eventType can be "mouseup", "mousedown", "mousemove", "doubleclick", or "click". The mouseX and mouseY specify the position of the mouse on the screen. The button argument specifies the mouse button clicked (e.g. "left").
func (*WebPage) SetClipRect ¶
SetClipRect sets the clipping rectangle used when rendering. Set to nil to render the entire webpage.
func (*WebPage) SetContent ¶
SetContent sets the content of the webpage.
func (*WebPage) SetContentAndURL ¶
SetContentAndURL sets the content and URL of the page.
func (*WebPage) SetCookies ¶
SetCookies sets a list of cookies visible to the current URL.
func (*WebPage) SetCustomHeaders ¶
SetCustomHeaders sets a list of additional headers sent with the web page.
This function does not support multiple headers with the same name. Only the first value for a header key will be used.
func (*WebPage) SetFrameContent ¶
SetFrameContent sets the content of the current frame.
func (*WebPage) SetLibraryPath ¶
SetLibraryPath sets the library path used by InjectJS().
func (*WebPage) SetNavigationLocked ¶
SetNavigationLocked sets whether navigation away from the page should be disabled.
func (*WebPage) SetOwnsPages ¶
SetOwnsPages sets whether this page owns pages opened in other windows.
func (*WebPage) SetPaperSize ¶
SetPaperSize sets the size of the web page when rendered as a PDF.
func (*WebPage) SetScrollPosition ¶
SetScrollPosition sets the current scroll position of the page.
func (*WebPage) SetSettings ¶
func (p *WebPage) SetSettings(settings WebPageSettings) error
SetSettings sets various settings on the web page.
The settings apply only during the initial call to the page.open function. Subsequent modification of the settings object will not have any impact.
func (*WebPage) SetViewportSize ¶
SetViewportSize sets the size of the viewport.
func (*WebPage) SetZoomFactor ¶
SetZoomFactor sets the zoom factor when rendering the page.
func (*WebPage) Settings ¶
func (p *WebPage) Settings() (WebPageSettings, error)
Settings returns the settings used on the web page.
func (*WebPage) SwitchToFocusedFrame ¶
SwitchToFocusedFrame changes the current frame to the frame that is in focus.
func (*WebPage) SwitchToFrameName ¶
SwitchToFrameName changes the current frame to a frame with a given name.
func (*WebPage) SwitchToFramePosition ¶
SwitchToFramePosition changes the current frame to the frame at the given position.
func (*WebPage) SwitchToMainFrame ¶
SwitchToMainFrame switches the current frame to the main frame.
func (*WebPage) SwitchToParentFrame ¶
SwitchToParentFrame switches the current frame to the parent of the current frame.
func (*WebPage) UploadFile ¶
UploadFile uploads a file to a form element specified by selector.
func (*WebPage) ViewportSize ¶
ViewportSize returns the size of the viewport on the browser.
func (*WebPage) WindowName ¶
WindowName returns the window name of the web page.
func (*WebPage) ZoomFactor ¶
ZoomFactor returns zoom factor when rendering the page.
type WebPageSettings ¶
type WebPageSettings struct { JavascriptEnabled bool LoadImages bool LocalToRemoteURLAccessEnabled bool UserAgent string Username string Password string XSSAuditingEnabled bool WebSecurityEnabled bool ResourceTimeout time.Duration }
WebPageSettings represents various settings on a web page.