https://github.com/segmentio/protocol
Testing component used to fake different protocols from the browser
https://github.com/segmentio/protocol
paused
Last synced: 11 months ago
JSON representation
Testing component used to fake different protocols from the browser
- Host: GitHub
- URL: https://github.com/segmentio/protocol
- Owner: segmentio
- License: mit
- Created: 2013-10-23T21:06:15.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2023-06-06T20:32:53.000Z (about 3 years ago)
- Last Synced: 2025-07-30T19:20:26.056Z (11 months ago)
- Topics: paused
- Language: JavaScript
- Homepage:
- Size: 35.2 KB
- Stars: 6
- Watchers: 37
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE
Awesome Lists containing this project
README
# protocol
> **Note**
> Segment has paused maintenance on this project, but may return it to an active status in the future. Issues and pull requests from external contributors are not being considered, although internal contributions may appear from time to time. The project remains available under its open source license for anyone to use.
[](https://circleci.com/gh/segmentio/protocol)
[](https://codecov.io/gh/segmentio/protocol)
Testing component used to fake protocols from the browser. Overrides `window.location.protocol` properties with fake ones using `Object.defineProperty`, so it won't work on IE8. Probably a good thing to only use in testing.
## Installation
```js
$ npm install @segment/protocol
```
## API
### #protocol()
Returns the current protocol that the document is using
```js
protocol(); // 'http:'
```
### #protocol(protocol)
When supplied with an argument, sets a custom protocol for the document.
```js
protocol('chrome-extension:');
protocol(); // 'chrome-extension:'
```
### #http()
Sets the protocol to be `http`
```js
protocol(); // 'file:'
protocol.http(); // 'http:'
```
### #https()
Sets the protocol to be `https:`
```js
protocol(); // 'file:'
protocol.https(); // 'https:'
```
### #reset()
Resets the protocol to be whatever it was at page load.
```js
protocol('x:');
protocol.reset();
protocol(); // 'http:'
```