{"id":22109291,"url":"https://github.com/pruvonet/cordova-network-interceptor","last_synced_at":"2026-05-11T02:15:53.553Z","repository":{"id":53677972,"uuid":"163691133","full_name":"PruvoNet/cordova-network-interceptor","owner":"PruvoNet","description":"network interceptor for cordova app that will fix all protocol relative url requests to use https","archived":false,"fork":false,"pushed_at":"2021-03-19T16:12:03.000Z","size":18,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-16T05:46:28.952Z","etag":null,"topics":["cordova","file","interceptor","javascript","network","plugin","protocol","relative","request"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PruvoNet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-31T18:52:26.000Z","updated_at":"2023-03-06T01:52:21.000Z","dependencies_parsed_at":"2022-09-10T05:40:15.485Z","dependency_job_id":null,"html_url":"https://github.com/PruvoNet/cordova-network-interceptor","commit_stats":null,"previous_names":["regevbr/cordova-network-interceptor"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PruvoNet%2Fcordova-network-interceptor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PruvoNet%2Fcordova-network-interceptor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PruvoNet%2Fcordova-network-interceptor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PruvoNet%2Fcordova-network-interceptor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PruvoNet","download_url":"https://codeload.github.com/PruvoNet/cordova-network-interceptor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245206534,"owners_count":20577582,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cordova","file","interceptor","javascript","network","plugin","protocol","relative","request"],"created_at":"2024-12-01T09:31:08.973Z","updated_at":"2026-05-11T02:15:53.490Z","avatar_url":"https://github.com/PruvoNet.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/regevbr/cordova-network-interceptor.svg?branch=master)](https://travis-ci.org/regevbr/cordova-network-interceptor)\n\n# cordova-network-interceptor\nNetwork interceptor for cordova app that will fix all protocol relative url requests to use https\n\nCordova 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`).   \n  \nIt is a common practice when writing modules, to reference urls to be used using the \"relative protocol\" `//` (e.g. `//www.googleapis.com/widget.js`).   \n\nIn cordova, this causes the url to be fetched with the `file:` protocol, which causes faliures and unloaded external libraries.   \nFor example,  `//www.googleapis.com/widget.js` will be translated to  `file://www.googleapis.com/widget.js`.   \n\nTo overcome the issue, the library will monkey patch a few things to force the urls to be using the `https:` protocol.\n\nThe library performs 4 operations:\n1. Patch the `document.createElement` method, which is used (amongst other things) to add dynamic scripts to be fetched by the browser.\nThe patch will alter the script `src` property if needed to use a proper protocol.\n2. 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.\n3. Patch the `XMLHttpRequest` object, to alter the url if needed to use a proper protocol, before the request is being executed.\n4. Patch the `fetch` API, to alter the url if needed to use a proper protocol, before the request is being executed.\n\nSo, 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.\n## Installation \n```sh\nnpm install cordova-network-interceptor --save\n```\nor\n```sh\nyarn add cordova-network-interceptor\n```\n## Usage\nAdd at the __TOP__ of the `\u003chead\u003e` element\n```html\n\u003cscript src=\"node_modules/cordova-network-interceptor/dist/index.js\"\u003e\u003c/script\u003e\n```\n### Credits\nThe code introduced here is inspired by a mesh up of code examples taken from:\n - https://www.phpied.com/intercepting-new-image-src-requests/\n - https://stackoverflow.com/a/629724/2242402\n - https://stackoverflow.com/questions/45425169/intercept-fetch-api-responses-and-request-in-javascript\n - https://medium.com/snips-ai/how-to-block-third-party-scripts-with-a-few-lines-of-javascript-f0b08b9c4c0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpruvonet%2Fcordova-network-interceptor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpruvonet%2Fcordova-network-interceptor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpruvonet%2Fcordova-network-interceptor/lists"}