npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-network-interceptor

v1.0.1

Published

network interceptor for cordova app that will fix all protocol relative url requests to use https

Downloads

9

Readme

Build Status

cordova-network-interceptor

Network interceptor for cordova app that will fix all protocol relative url requests to use https

Cordova is essentially a web view that serves files from the file system. As such, the protocl of the "url" it uses is file: (e.g. file://android_assets/www/index.html).

It is a common practice when writing modules, to reference urls to be used using the "relative protocol" // (e.g. //www.googleapis.com/widget.js).

In cordova, this causes the url to be fetched with the file: protocol, which causes faliures and unloaded external libraries.
For example, //www.googleapis.com/widget.js will be translated to file://www.googleapis.com/widget.js.

To overcome the issue, the library will monkey patch a few things to force the urls to be using the https: protocol.

The library performs 4 operations:

  1. Patch the document.createElement method, which is used (amongst other things) to add dynamic scripts to be fetched by the browser. The patch will alter the script src property if needed to use a proper protocol.
  2. Patch the Image constructor, which is commonly used to fire pixels. The patch will alter the image src property if needed to use a proper protocol.
  3. Patch the XMLHttpRequest object, to alter the url if needed to use a proper protocol, before the request is being executed.
  4. Patch the fetch API, to alter the url if needed to use a proper protocol, before the request is being executed.

So, for example, if any script, no matter how fetched and when, will use //www.googleapis.com/widget.js as its source, it will be translated and fetched by the https://www.googleapis.com/widget.js correct url.

Installation

npm install cordova-network-interceptor --save

or

yarn add cordova-network-interceptor

Usage

Add at the TOP of the <head> element

<script src="node_modules/cordova-network-interceptor/dist/index.js"></script>

Credits

The code introduced here is inspired by a mesh up of code examples taken from:

  • https://www.phpied.com/intercepting-new-image-src-requests/
  • https://stackoverflow.com/a/629724/2242402
  • https://stackoverflow.com/questions/45425169/intercept-fetch-api-responses-and-request-in-javascript
  • https://medium.com/snips-ai/how-to-block-third-party-scripts-with-a-few-lines-of-javascript-f0b08b9c4c0