https://github.com/airtap/abstract-browser
Interface for opening and closing a browser.
https://github.com/airtap/abstract-browser
Last synced: 8 months ago
JSON representation
Interface for opening and closing a browser.
- Host: GitHub
- URL: https://github.com/airtap/abstract-browser
- Owner: airtap
- License: mit
- Created: 2020-07-14T20:28:35.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-07-01T21:05:18.000Z (over 1 year ago)
- Last Synced: 2025-02-18T02:06:11.862Z (8 months ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# abstract-browser
**Interface for opening and closing a browser.** Uses [`nanoresource`](https://github.com/mafintosh/nanoresource) for state management, [`browser-manifest`](https://github.com/airtap/browser-manifest) for metadata. Pairs well with [`browser-provider`](https://github.com/airtap/browser-provider).
[](https://www.npmjs.org/package/abstract-browser)
[](https://www.npmjs.org/package/abstract-browser)
[](https://travis-ci.com/airtap/abstract-browser)
[](https://standardjs.com)## Usage
With promises:
```js
const Browser = require('abstract-browser').promisesclass MyBrowser extends Browser {
async _open () {
// open the browser
console.log('opening', this.target.url)
}async _close () {
// close the browser
}
}
```With callbacks:
```js
const Browser = require('abstract-browser')class MyBrowser extends Browser {
_open (callback) {
// ..
}_close (callback) {
// ..
}
}
```## API
### `browser = new Browser(manifest, target)`
Constructor. Takes a [`browser-manifest`](https://github.com/airtap/browser-manifest) and a `target` object in the form of `{ url }`.
Implementors are free to change the signature of their constructor. User-facing options specific to an implementation should be passed in via `manifest.options`.
### `browser.open([callback])`
Open the browser. Returns a promise if no callback is provided.
### `browser.close([callback])`
Close the browser. Returns a promise if no callback is provided.
### `browser.status(ok[, callback])`
Set status by a boolean `ok`. Returns a promise if no callback is provided. Useful for remote browsers like Sauce Labs where you can set the remote job status e.g. after running tests on a browser.
### `browser.manifest`
The manifest that was passed to the constructor.
### `browser.target`
The target that was passed to the constructor.
## Events
Browsers may emit `error` events. It's recommended to only do so after `open()` has completed and not after `close()` has been called. The [`transient-error`](https://github.com/vweevers/transient-error) module may be used to signal that the error is temporary and that running (a new instance of) the browser can be retried.
## Install
With [npm](https://npmjs.org) do:
```
npm install abstract-browser
```## License
[MIT](LICENSE.md) © 2020-present Airtap contributors