コード例 #1
0
ファイル: dom.go プロジェクト: stanleyhlng/gcd
// PushNodesByBackendIdsToFrontend - Requests that a batch of nodes is sent to the caller given their backend node ids.
// backendNodeIds - The array of backend node ids.
// Returns -  nodeIds - The array of ids of pushed nodes that correspond to the backend ids specified in backendNodeIds.
func (c *DOM) PushNodesByBackendIdsToFrontend(backendNodeIds int) ([]int, error) {
	paramRequest := make(map[string]interface{}, 1)
	paramRequest["backendNodeIds"] = backendNodeIds
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "DOM.pushNodesByBackendIdsToFrontend", Params: paramRequest})
	if err != nil {
		return nil, err
	}

	var chromeData struct {
		Result struct {
			NodeIds []int
		}
	}

	if resp == nil {
		return nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return nil, err
	}

	return chromeData.Result.NodeIds, nil
}
コード例 #2
0
ファイル: network.go プロジェクト: stanleyhlng/gcd
// GetResponseBody - Returns content served for the given request.
// requestId - Identifier of the network request to get content for.
// Returns -  body - Response body. base64Encoded - True, if content was sent as base64.
func (c *Network) GetResponseBody(requestId string) (string, bool, error) {
	paramRequest := make(map[string]interface{}, 1)
	paramRequest["requestId"] = requestId
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "Network.getResponseBody", Params: paramRequest})
	if err != nil {
		return "", false, err
	}

	var chromeData struct {
		Result struct {
			Body          string
			Base64Encoded bool
		}
	}

	if resp == nil {
		return "", false, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return "", false, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return "", false, err
	}

	return chromeData.Result.Body, chromeData.Result.Base64Encoded, nil
}
コード例 #3
0
ファイル: network.go プロジェクト: stanleyhlng/gcd
// CanEmulateNetworkConditions - Tells whether emulation of network conditions is supported.
// Returns -  result - True if emulation of network conditions is supported.
func (c *Network) CanEmulateNetworkConditions() (bool, error) {
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "Network.canEmulateNetworkConditions"})
	if err != nil {
		return false, err
	}

	var chromeData struct {
		Result struct {
			Result bool
		}
	}

	if resp == nil {
		return false, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return false, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return false, err
	}

	return chromeData.Result.Result, nil
}
コード例 #4
0
ファイル: page.go プロジェクト: stanleyhlng/gcd
// GetResourceTree - Returns present frame / resource tree structure.
// Returns -  frameTree - Present frame / resource tree structure.
func (c *Page) GetResourceTree() (*PageFrameResourceTree, error) {
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "Page.getResourceTree"})
	if err != nil {
		return nil, err
	}

	var chromeData struct {
		Result struct {
			FrameTree *PageFrameResourceTree
		}
	}

	if resp == nil {
		return nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return nil, err
	}

	return chromeData.Result.FrameTree, nil
}
コード例 #5
0
ファイル: page.go プロジェクト: stanleyhlng/gcd
// SearchInResource - Searches for given string in resource content.
// frameId - Frame id for resource to search in.
// url - URL of the resource to search in.
// query - String to search for.
// caseSensitive - If true, search is case sensitive.
// isRegex - If true, treats string parameter as regex.
// Returns -  result - List of search matches.
func (c *Page) SearchInResource(frameId string, url string, query string, caseSensitive bool, isRegex bool) ([]*DebuggerSearchMatch, error) {
	paramRequest := make(map[string]interface{}, 5)
	paramRequest["frameId"] = frameId
	paramRequest["url"] = url
	paramRequest["query"] = query
	paramRequest["caseSensitive"] = caseSensitive
	paramRequest["isRegex"] = isRegex
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "Page.searchInResource", Params: paramRequest})
	if err != nil {
		return nil, err
	}

	var chromeData struct {
		Result struct {
			Result []*DebuggerSearchMatch
		}
	}

	if resp == nil {
		return nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return nil, err
	}

	return chromeData.Result.Result, nil
}
コード例 #6
0
ファイル: indexeddb.go プロジェクト: stanleyhlng/gcd
// RequestDatabaseNames - Requests database names for given security origin.
// securityOrigin - Security origin.
// Returns -  databaseNames - Database names for origin.
func (c *IndexedDB) RequestDatabaseNames(securityOrigin string) ([]string, error) {
	paramRequest := make(map[string]interface{}, 1)
	paramRequest["securityOrigin"] = securityOrigin
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "IndexedDB.requestDatabaseNames", Params: paramRequest})
	if err != nil {
		return nil, err
	}

	var chromeData struct {
		Result struct {
			DatabaseNames []string
		}
	}

	if resp == nil {
		return nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return nil, err
	}

	return chromeData.Result.DatabaseNames, nil
}
コード例 #7
0
ファイル: page.go プロジェクト: stanleyhlng/gcd
// Navigate - Navigates current page to the given URL.
// url - URL to navigate the page to.
// Returns -  frameId - Frame id that will be navigated.
func (c *Page) Navigate(url string) (string, error) {
	paramRequest := make(map[string]interface{}, 1)
	paramRequest["url"] = url
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "Page.navigate", Params: paramRequest})
	if err != nil {
		return "", err
	}

	var chromeData struct {
		Result struct {
			FrameId string
		}
	}

	if resp == nil {
		return "", &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return "", &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return "", err
	}

	return chromeData.Result.FrameId, nil
}
コード例 #8
0
ファイル: cachestorage.go プロジェクト: stanleyhlng/gcd
// RequestEntries - Requests data from cache.
// cacheId - ID of cache to get entries from.
// skipCount - Number of records to skip.
// pageSize - Number of records to fetch.
// Returns -  cacheDataEntries - Array of object store data entries. hasMore - If true, there are more entries to fetch in the given range.
func (c *CacheStorage) RequestEntries(cacheId string, skipCount int, pageSize int) ([]*CacheStorageDataEntry, bool, error) {
	paramRequest := make(map[string]interface{}, 3)
	paramRequest["cacheId"] = cacheId
	paramRequest["skipCount"] = skipCount
	paramRequest["pageSize"] = pageSize
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "CacheStorage.requestEntries", Params: paramRequest})
	if err != nil {
		return nil, false, err
	}

	var chromeData struct {
		Result struct {
			CacheDataEntries []*CacheStorageDataEntry
			HasMore          bool
		}
	}

	if resp == nil {
		return nil, false, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return nil, false, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return nil, false, err
	}

	return chromeData.Result.CacheDataEntries, chromeData.Result.HasMore, nil
}
コード例 #9
0
ファイル: filesystem.go プロジェクト: stanleyhlng/gcd
// RequestFileSystemRoot - Returns root directory of the FileSystem, if exists.
// origin - Security origin of requesting FileSystem. One of frames in current page needs to have this security origin.
// type - FileSystem type of requesting FileSystem.
// Returns -  errorCode - 0, if no error. Otherwise, errorCode is set to FileError::ErrorCode value. root - Contains root of the requested FileSystem if the command completed successfully.
func (c *FileSystem) RequestFileSystemRoot(origin string, theType string) (int, *FileSystemEntry, error) {
	paramRequest := make(map[string]interface{}, 2)
	paramRequest["origin"] = origin
	paramRequest["type"] = theType
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "FileSystem.requestFileSystemRoot", Params: paramRequest})
	if err != nil {
		return 0, nil, err
	}

	var chromeData struct {
		Result struct {
			ErrorCode int
			Root      *FileSystemEntry
		}
	}

	if resp == nil {
		return 0, nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return 0, nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return 0, nil, err
	}

	return chromeData.Result.ErrorCode, chromeData.Result.Root, nil
}
コード例 #10
0
ファイル: io.go プロジェクト: stanleyhlng/gcd
// Read - Read a chunk of the stream
// handle - Handle of the stream to read.
// offset - Seek to the specified offset before reading (if not specificed, proceed with offset following the last read).
// size - Maximum number of bytes to read (left upon the agent discretion if not specified).
// Returns -  data - Data that were read. eof - Set if the end-of-file condition occured while reading.
func (c *IO) Read(handle string, offset int, size int) (string, bool, error) {
	paramRequest := make(map[string]interface{}, 3)
	paramRequest["handle"] = handle
	paramRequest["offset"] = offset
	paramRequest["size"] = size
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "IO.read", Params: paramRequest})
	if err != nil {
		return "", false, err
	}

	var chromeData struct {
		Result struct {
			Data string
			Eof  bool
		}
	}

	if resp == nil {
		return "", false, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return "", false, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return "", false, err
	}

	return chromeData.Result.Data, chromeData.Result.Eof, nil
}
コード例 #11
0
ファイル: heapprofiler.go プロジェクト: stanleyhlng/gcd
// GetObjectByHeapObjectId -
// objectId -
// objectGroup - Symbolic group name that can be used to release multiple objects.
// Returns -  result - Evaluation result.
func (c *HeapProfiler) GetObjectByHeapObjectId(objectId string, objectGroup string) (*RuntimeRemoteObject, error) {
	paramRequest := make(map[string]interface{}, 2)
	paramRequest["objectId"] = objectId
	paramRequest["objectGroup"] = objectGroup
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "HeapProfiler.getObjectByHeapObjectId", Params: paramRequest})
	if err != nil {
		return nil, err
	}

	var chromeData struct {
		Result struct {
			Result *RuntimeRemoteObject
		}
	}

	if resp == nil {
		return nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return nil, err
	}

	return chromeData.Result.Result, nil
}
コード例 #12
0
ファイル: dom.go プロジェクト: stanleyhlng/gcd
// GetNodeForLocation - Returns node id at given location.
// x - X coordinate.
// y - Y coordinate.
// Returns -  nodeId - Id of the node at given coordinates.
func (c *DOM) GetNodeForLocation(x int, y int) (int, error) {
	paramRequest := make(map[string]interface{}, 2)
	paramRequest["x"] = x
	paramRequest["y"] = y
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "DOM.getNodeForLocation", Params: paramRequest})
	if err != nil {
		return 0, err
	}

	var chromeData struct {
		Result struct {
			NodeId int
		}
	}

	if resp == nil {
		return 0, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return 0, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return 0, err
	}

	return chromeData.Result.NodeId, nil
}
コード例 #13
0
ファイル: dom.go プロジェクト: stanleyhlng/gcd
// GetBoxModel - Returns boxes for the currently selected nodes.
// nodeId - Id of the node to get box model for.
// Returns -  model - Box model for the node.
func (c *DOM) GetBoxModel(nodeId int) (*DOMBoxModel, error) {
	paramRequest := make(map[string]interface{}, 1)
	paramRequest["nodeId"] = nodeId
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "DOM.getBoxModel", Params: paramRequest})
	if err != nil {
		return nil, err
	}

	var chromeData struct {
		Result struct {
			Model *DOMBoxModel
		}
	}

	if resp == nil {
		return nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return nil, err
	}

	return chromeData.Result.Model, nil
}
コード例 #14
0
ファイル: dom.go プロジェクト: stanleyhlng/gcd
// MoveTo - Moves node into the new container, places it before the given anchor.
// nodeId - Id of the node to move.
// targetNodeId - Id of the element to drop the moved node into.
// insertBeforeNodeId - Drop node before this one (if absent, the moved node becomes the last child of <code>targetNodeId</code>).
// Returns -  nodeId - New id of the moved node.
func (c *DOM) MoveTo(nodeId int, targetNodeId int, insertBeforeNodeId int) (int, error) {
	paramRequest := make(map[string]interface{}, 3)
	paramRequest["nodeId"] = nodeId
	paramRequest["targetNodeId"] = targetNodeId
	paramRequest["insertBeforeNodeId"] = insertBeforeNodeId
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "DOM.moveTo", Params: paramRequest})
	if err != nil {
		return 0, err
	}

	var chromeData struct {
		Result struct {
			NodeId int
		}
	}

	if resp == nil {
		return 0, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return 0, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return 0, err
	}

	return chromeData.Result.NodeId, nil
}
コード例 #15
0
ファイル: css.go プロジェクト: stanleyhlng/gcd
// GetMediaQueries - Returns all media queries parsed by the rendering engine.
// Returns -  medias -
func (c *CSS) GetMediaQueries() ([]*CSSCSSMedia, error) {
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "CSS.getMediaQueries"})
	if err != nil {
		return nil, err
	}

	var chromeData struct {
		Result struct {
			Medias []*CSSCSSMedia
		}
	}

	if resp == nil {
		return nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return nil, err
	}

	return chromeData.Result.Medias, nil
}
コード例 #16
0
ファイル: filesystem.go プロジェクト: stanleyhlng/gcd
// RequestDirectoryContent - Returns content of the directory.
// url - URL of the directory that the frontend is requesting to read from.
// Returns -  errorCode - 0, if no error. Otherwise, errorCode is set to FileError::ErrorCode value. entries - Contains all entries on directory if the command completed successfully.
func (c *FileSystem) RequestDirectoryContent(url string) (int, []*FileSystemEntry, error) {
	paramRequest := make(map[string]interface{}, 1)
	paramRequest["url"] = url
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "FileSystem.requestDirectoryContent", Params: paramRequest})
	if err != nil {
		return 0, nil, err
	}

	var chromeData struct {
		Result struct {
			ErrorCode int
			Entries   []*FileSystemEntry
		}
	}

	if resp == nil {
		return 0, nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return 0, nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return 0, nil, err
	}

	return chromeData.Result.ErrorCode, chromeData.Result.Entries, nil
}
コード例 #17
0
ファイル: domstorage.go プロジェクト: stanleyhlng/gcd
// GetDOMStorageItems -
// storageId -
// Returns -  entries -
func (c *DOMStorage) GetDOMStorageItems(storageId *DOMStorageStorageId) ([]string, error) {
	paramRequest := make(map[string]interface{}, 1)
	paramRequest["storageId"] = storageId
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "DOMStorage.getDOMStorageItems", Params: paramRequest})
	if err != nil {
		return nil, err
	}

	var chromeData struct {
		Result struct {
			Entries []string
		}
	}

	if resp == nil {
		return nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return nil, err
	}

	return chromeData.Result.Entries, nil
}
コード例 #18
0
ファイル: database.go プロジェクト: stanleyhlng/gcd
// ExecuteSQL -
// databaseId -
// query -
// Returns -  columnNames -  values -  sqlError -
func (c *Database) ExecuteSQL(databaseId string, query string) ([]string, []string, *DatabaseError, error) {
	paramRequest := make(map[string]interface{}, 2)
	paramRequest["databaseId"] = databaseId
	paramRequest["query"] = query
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "Database.executeSQL", Params: paramRequest})
	if err != nil {
		return nil, nil, nil, err
	}

	var chromeData struct {
		Result struct {
			ColumnNames []string
			Values      []string
			SqlError    *DatabaseError
		}
	}

	if resp == nil {
		return nil, nil, nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return nil, nil, nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return nil, nil, nil, err
	}

	return chromeData.Result.ColumnNames, chromeData.Result.Values, chromeData.Result.SqlError, nil
}
コード例 #19
0
ファイル: page.go プロジェクト: stanleyhlng/gcd
// AddScriptToEvaluateOnLoad -
// scriptSource -
// Returns -  identifier - Identifier of the added script.
func (c *Page) AddScriptToEvaluateOnLoad(scriptSource string) (string, error) {
	paramRequest := make(map[string]interface{}, 1)
	paramRequest["scriptSource"] = scriptSource
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "Page.addScriptToEvaluateOnLoad", Params: paramRequest})
	if err != nil {
		return "", err
	}

	var chromeData struct {
		Result struct {
			Identifier string
		}
	}

	if resp == nil {
		return "", &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return "", &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return "", err
	}

	return chromeData.Result.Identifier, nil
}
コード例 #20
0
ファイル: css.go プロジェクト: stanleyhlng/gcd
// GetMatchedStylesForNode - Returns requested styles for a DOM node identified by <code>nodeId</code>.
// nodeId -
// excludePseudo - Whether to exclude pseudo styles (default: false).
// excludeInherited - Whether to exclude inherited styles (default: false).
// Returns -  matchedCSSRules - CSS rules matching this node, from all applicable stylesheets. pseudoElements - Pseudo style matches for this node. inherited - A chain of inherited styles (from the immediate node parent up to the DOM tree root).
func (c *CSS) GetMatchedStylesForNode(nodeId int, excludePseudo bool, excludeInherited bool) ([]*CSSRuleMatch, []*CSSPseudoIdMatches, []*CSSInheritedStyleEntry, error) {
	paramRequest := make(map[string]interface{}, 3)
	paramRequest["nodeId"] = nodeId
	paramRequest["excludePseudo"] = excludePseudo
	paramRequest["excludeInherited"] = excludeInherited
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "CSS.getMatchedStylesForNode", Params: paramRequest})
	if err != nil {
		return nil, nil, nil, err
	}

	var chromeData struct {
		Result struct {
			MatchedCSSRules []*CSSRuleMatch
			PseudoElements  []*CSSPseudoIdMatches
			Inherited       []*CSSInheritedStyleEntry
		}
	}

	if resp == nil {
		return nil, nil, nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return nil, nil, nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return nil, nil, nil, err
	}

	return chromeData.Result.MatchedCSSRules, chromeData.Result.PseudoElements, chromeData.Result.Inherited, nil
}
コード例 #21
0
ファイル: page.go プロジェクト: stanleyhlng/gcd
// GetNavigationHistory - Returns navigation history for the current page.
// Returns -  currentIndex - Index of the current navigation history entry. entries - Array of navigation history entries.
func (c *Page) GetNavigationHistory() (int, []*PageNavigationEntry, error) {
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "Page.getNavigationHistory"})
	if err != nil {
		return 0, nil, err
	}

	var chromeData struct {
		Result struct {
			CurrentIndex int
			Entries      []*PageNavigationEntry
		}
	}

	if resp == nil {
		return 0, nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return 0, nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return 0, nil, err
	}

	return chromeData.Result.CurrentIndex, chromeData.Result.Entries, nil
}
コード例 #22
0
ファイル: css.go プロジェクト: stanleyhlng/gcd
// GetPlatformFontsForNode - Requests information about platform fonts which we used to render child TextNodes in the given node.
// nodeId -
// Returns -  fonts - Usage statistics for every employed platform font.
func (c *CSS) GetPlatformFontsForNode(nodeId int) ([]*CSSPlatformFontUsage, error) {
	paramRequest := make(map[string]interface{}, 1)
	paramRequest["nodeId"] = nodeId
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "CSS.getPlatformFontsForNode", Params: paramRequest})
	if err != nil {
		return nil, err
	}

	var chromeData struct {
		Result struct {
			Fonts []*CSSPlatformFontUsage
		}
	}

	if resp == nil {
		return nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return nil, err
	}

	return chromeData.Result.Fonts, nil
}
コード例 #23
0
ファイル: page.go プロジェクト: stanleyhlng/gcd
// GetResourceContent - Returns content of the given resource.
// frameId - Frame id to get resource for.
// url - URL of the resource to get content for.
// Returns -  content - Resource content. base64Encoded - True, if content was served as base64.
func (c *Page) GetResourceContent(frameId string, url string) (string, bool, error) {
	paramRequest := make(map[string]interface{}, 2)
	paramRequest["frameId"] = frameId
	paramRequest["url"] = url
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "Page.getResourceContent", Params: paramRequest})
	if err != nil {
		return "", false, err
	}

	var chromeData struct {
		Result struct {
			Content       string
			Base64Encoded bool
		}
	}

	if resp == nil {
		return "", false, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return "", false, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return "", false, err
	}

	return chromeData.Result.Content, chromeData.Result.Base64Encoded, nil
}
コード例 #24
0
ファイル: css.go プロジェクト: stanleyhlng/gcd
// SetMediaText - Modifies the rule selector.
// styleSheetId -
// range -
// text -
// Returns -  media - The resulting CSS media rule after modification.
func (c *CSS) SetMediaText(styleSheetId string, theRange *CSSSourceRange, text string) (*CSSCSSMedia, error) {
	paramRequest := make(map[string]interface{}, 3)
	paramRequest["styleSheetId"] = styleSheetId
	paramRequest["range"] = theRange
	paramRequest["text"] = text
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "CSS.setMediaText", Params: paramRequest})
	if err != nil {
		return nil, err
	}

	var chromeData struct {
		Result struct {
			Media *CSSCSSMedia
		}
	}

	if resp == nil {
		return nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return nil, err
	}

	return chromeData.Result.Media, nil
}
コード例 #25
0
ファイル: page.go プロジェクト: stanleyhlng/gcd
// CaptureScreenshot - Capture page screenshot.
// Returns -  data - Base64-encoded image data (PNG).
func (c *Page) CaptureScreenshot() (string, error) {
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "Page.captureScreenshot"})
	if err != nil {
		return "", err
	}

	var chromeData struct {
		Result struct {
			Data string
		}
	}

	if resp == nil {
		return "", &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return "", &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return "", err
	}

	return chromeData.Result.Data, nil
}
コード例 #26
0
ファイル: css.go プロジェクト: stanleyhlng/gcd
// CreateStyleSheet - Creates a new special "via-inspector" stylesheet in the frame with given <code>frameId</code>.
// frameId - Identifier of the frame where "via-inspector" stylesheet should be created.
// Returns -  styleSheetId - Identifier of the created "via-inspector" stylesheet.
func (c *CSS) CreateStyleSheet(frameId string) (string, error) {
	paramRequest := make(map[string]interface{}, 1)
	paramRequest["frameId"] = frameId
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "CSS.createStyleSheet", Params: paramRequest})
	if err != nil {
		return "", err
	}

	var chromeData struct {
		Result struct {
			StyleSheetId string
		}
	}

	if resp == nil {
		return "", &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return "", &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return "", err
	}

	return chromeData.Result.StyleSheetId, nil
}
コード例 #27
0
ファイル: network.go プロジェクト: stanleyhlng/gcd
// GetCookies - Returns all browser cookies. Depending on the backend support, will return detailed cookie information in the <code>cookies</code> field.
// Returns -  cookies - Array of cookie objects.
func (c *Network) GetCookies() ([]*NetworkCookie, error) {
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "Network.getCookies"})
	if err != nil {
		return nil, err
	}

	var chromeData struct {
		Result struct {
			Cookies []*NetworkCookie
		}
	}

	if resp == nil {
		return nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return nil, err
	}

	return chromeData.Result.Cookies, nil
}
コード例 #28
0
ファイル: css.go プロジェクト: stanleyhlng/gcd
// AddRule - Inserts a new rule with the given <code>ruleText</code> in a stylesheet with given <code>styleSheetId</code>, at the position specified by <code>location</code>.
// styleSheetId - The css style sheet identifier where a new rule should be inserted.
// ruleText - The text of a new rule.
// location - Text position of a new rule in the target style sheet.
// Returns -  rule - The newly created rule.
func (c *CSS) AddRule(styleSheetId string, ruleText string, location *CSSSourceRange) (*CSSCSSRule, error) {
	paramRequest := make(map[string]interface{}, 3)
	paramRequest["styleSheetId"] = styleSheetId
	paramRequest["ruleText"] = ruleText
	paramRequest["location"] = location
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "CSS.addRule", Params: paramRequest})
	if err != nil {
		return nil, err
	}

	var chromeData struct {
		Result struct {
			Rule *CSSCSSRule
		}
	}

	if resp == nil {
		return nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return nil, err
	}

	return chromeData.Result.Rule, nil
}
コード例 #29
0
ファイル: network.go プロジェクト: stanleyhlng/gcd
// GetCertificateDetails - Returns details for the given certificate.
// certificateId - ID of the certificate to get details for.
// Returns -  result - Certificate details.
func (c *Network) GetCertificateDetails(certificateId int) (*NetworkCertificateDetails, error) {
	paramRequest := make(map[string]interface{}, 1)
	paramRequest["certificateId"] = certificateId
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "Network.getCertificateDetails", Params: paramRequest})
	if err != nil {
		return nil, err
	}

	var chromeData struct {
		Result struct {
			Result *NetworkCertificateDetails
		}
	}

	if resp == nil {
		return nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return nil, err
	}

	return chromeData.Result.Result, nil
}
コード例 #30
0
ファイル: dom.go プロジェクト: stanleyhlng/gcd
// GetSearchResults - Returns search results from given <code>fromIndex</code> to given <code>toIndex</code> from the sarch with the given identifier.
// searchId - Unique search session identifier.
// fromIndex - Start index of the search result to be returned.
// toIndex - End index of the search result to be returned.
// Returns -  nodeIds - Ids of the search result nodes.
func (c *DOM) GetSearchResults(searchId string, fromIndex int, toIndex int) ([]int, error) {
	paramRequest := make(map[string]interface{}, 3)
	paramRequest["searchId"] = searchId
	paramRequest["fromIndex"] = fromIndex
	paramRequest["toIndex"] = toIndex
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "DOM.getSearchResults", Params: paramRequest})
	if err != nil {
		return nil, err
	}

	var chromeData struct {
		Result struct {
			NodeIds []int
		}
	}

	if resp == nil {
		return nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return nil, err
	}

	return chromeData.Result.NodeIds, nil
}