https://github.com/dimacpp/webview-query
Utility node.js library for Chrome Webview traversal and manipulation.
https://github.com/dimacpp/webview-query
node-js node-webkit nwjs
Last synced: 6 months ago
JSON representation
Utility node.js library for Chrome Webview traversal and manipulation.
- Host: GitHub
- URL: https://github.com/dimacpp/webview-query
- Owner: dimacpp
- License: mit
- Created: 2018-01-12T06:56:47.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-09-01T09:34:47.000Z (over 5 years ago)
- Last Synced: 2025-05-23T01:25:24.587Z (8 months ago)
- Topics: node-js, node-webkit, nwjs
- Language: JavaScript
- Size: 50.8 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# webview-query
Utility node.js library for [Chrome Webview](https://developer.chrome.com/apps/tags/webview) traversal and manipulation.
[]()
## Install
`npm install webview-query --save`
## Example
For example, you have NW.js app with webview tag within.
`html:`
`js:`
const { Webview } = require('webview-query');
const webview = new Webview(view1);
// inside async function:
await webview.location('https://github.com');
console.log(await webview.title());
// -> "The world's leading software development platform · GitHub"
console.log(await webview.text('.jumbotron h1'));
// -> "Built for developers"
webview.val('form.home-hero-signup input[id="user[login]"]', 'Hello GitHub!');
## Classes
## External
- webview
-
Chrome webview element
## Webview
**Kind**: global class
* [Webview](#Webview)
* [new Webview(webview)](#new_Webview_new)
* [.webview](#Webview+webview) : [webview](#external_webview)
* [.runJs(code)](#Webview+runJs) ⇒ Promise
* [.title(value)](#Webview+title) ⇒ Promise
* [.location(value)](#Webview+location) ⇒ Promise
* [.exists(selector)](#Webview+exists) ⇒ Promise.<boolean>
* [.length(selector)](#Webview+length) ⇒ Promise.<number>
* [.val(selector, value)](#Webview+val) ⇒ Promise
* [.attr(selector, attribute, value)](#Webview+attr) ⇒ Promise
* [.text(selector, value)](#Webview+text) ⇒ Promise
* [.html(selector, value, [options])](#Webview+html) ⇒ Promise
* [.click(selector)](#Webview+click) ⇒ Promise
### new Webview(webview)
Webview is a class for Chrome webview promise-based traversal and manipulation.
| Param | Type | Description |
| --- | --- | --- |
| webview | [webview](#external_webview) | Chrome webview element. |
### webview.webview : [webview](#external_webview)
**Kind**: instance property of [Webview](#Webview)
### webview.runJs(code) ⇒ Promise
Run arbitrary javascript code inside webview context.
**Kind**: instance method of [Webview](#Webview)
**Returns**: Promise - Promise object represents the result of the script.
| Param | Type | Description |
| --- | --- | --- |
| code | string | Javascript code. |
### webview.title(value) ⇒ Promise
Set webview document new title.
**Kind**: instance method of [Webview](#Webview)
| Param | Type | Description |
| --- | --- | --- |
| value | string | New document title. |
### webview.location(value) ⇒ Promise
Set webview new location.
**Kind**: instance method of [Webview](#Webview)
| Param | Type | Description |
| --- | --- | --- |
| value | string | URL or path to local file. |
### webview.exists(selector) ⇒ Promise.<boolean>
Check the existence of an element(s).
**Kind**: instance method of [Webview](#Webview)
**Returns**: Promise.<boolean> - Promise object represents the element(s) existence.
| Param | Type | Description |
| --- | --- | --- |
| selector | string | CSS selector. |
### webview.length(selector) ⇒ Promise.<number>
Return number of elements matched by selector.
**Kind**: instance method of [Webview](#Webview)
**Returns**: Promise.<number> - Promise object represents the number of elements currently matched..
| Param | Type | Description |
| --- | --- | --- |
| selector | string | CSS selector. |
### webview.val(selector, value) ⇒ Promise
Set the value of every matched element.
**Kind**: instance method of [Webview](#Webview)
| Param | Type | Description |
| --- | --- | --- |
| selector | string | CSS selector. |
| value | string | Value to set. |
### webview.attr(selector, attribute, value) ⇒ Promise
Set an attribute for every matched element.
**Kind**: instance method of [Webview](#Webview)
| Param | Type | Description |
| --- | --- | --- |
| selector | string | CSS selector. |
| attribute | string | The name of the attribute to set. |
| value | string | A value to set for the attribute.. |
### webview.text(selector, value) ⇒ Promise
Set the text contents of the matched elements.
**Kind**: instance method of [Webview](#Webview)
| Param | Type | Description |
| --- | --- | --- |
| selector | string | CSS selector. |
| value | string | The text to set as the content of each matched element. |
### webview.html(selector, value, [options]) ⇒ Promise
Set the HTML contents of every matched element.
**Kind**: instance method of [Webview](#Webview)
| Param | Type | Description |
| --- | --- | --- |
| selector | string | CSS selector. |
| value | string | A string of HTML to set as the content of each matched element. |
| [options] | object | Options. |
| [options.outer] | boolean | If true the result will be outer HTML, inner HTML otherwise. |
### webview.click(selector) ⇒ Promise
Execute click action for the matched element(s).
**Kind**: instance method of [Webview](#Webview)
| Param | Type | Description |
| --- | --- | --- |
| selector | string | CSS selector. |
## webview
Chrome webview element
**Kind**: global external
**See**: [https://developer.chrome.com/apps/tags/webview](https://developer.chrome.com/apps/tags/webview)