├── package-firefox.txt
├── package.sh
├── package.bat
├── TODO.txt
├── jsconfig.json
├── README.md
├── src
├── options.js
├── options.xhtml
├── icons
│ ├── icon.svg
│ └── icon-light.svg
└── background.js
├── .gitattributes
├── LICENSE.md
├── manifest.json
├── .gitignore
├── LICENSE-3RD-PARTY.md
└── lib
└── browser-polyfill.js
/package-firefox.txt:
--------------------------------------------------------------------------------
1 | src
2 | LICENSE-3RD-PARTY.md
3 | LICENSE.md
4 | manifest.json
5 | README.md
6 |
--------------------------------------------------------------------------------
/package.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/bash
2 | rm -r -f dist/Firefox
3 | 7za a -tzip dist/Firefox/ToggleResistFingerprinting.zip @package-firefox.txt
4 |
--------------------------------------------------------------------------------
/package.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | rmdir /S /Q .\dist\Firefox
4 | .\lib\7za.exe a -tzip .\dist\Firefox\ToggleResistFingerprinting.zip @package-firefox.txt
--------------------------------------------------------------------------------
/TODO.txt:
--------------------------------------------------------------------------------
1 | If we can get a good way to get the last window or the screen size we can recreate the normal windowed/maximized functionality
2 | Resist fingerprinting interferes with the "screen" object values.
3 |
4 | Refactor the code to get rid of the global "enabled" state.
5 |
--------------------------------------------------------------------------------
/jsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "checkJs": true,
4 | "target": "es2019",
5 | "baseUrl": "."
6 | },
7 | "exclude": [
8 | "node_modules",
9 | "**/node_modules/*"
10 | ],
11 | "files": [
12 | "./typings/index.d.ts",
13 | "./typings/firefox-webext-browser/index.d.ts"
14 | ],
15 | "include": [
16 | "./src/**/*"
17 | ]
18 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Adds a button to the navigation bar to toggle the "resist fingerprinting" setting; to help prevent websites from fingerprinting your browser for tracking purposes.
2 |
3 | Enabling the "resist fingerprinting" setting may break some websites. Information about the "resist fingerprinting" setting can be found at [https://wiki.mozilla.org/Security/Fingerprinting](https://wiki.mozilla.org/Security/Fingerprinting).
4 |
5 | Icon made by [Freepik](https://www.freepik.com/) from Flaticon is licensed by [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/)
6 |
--------------------------------------------------------------------------------
/src/options.js:
--------------------------------------------------------------------------------
1 | (async function () {
2 | "use strict";
3 |
4 | //Bit-flag enum
5 | const MaximizeWindowTypes = {
6 | 0: "None",
7 | 1: "Normal",
8 | 2: "Private",
9 | "None": 0,
10 | "Normal": 1,
11 | "Private": 2,
12 | };
13 |
14 | const maximizeWindowTypes = /** @type {HTMLSelectElement} */ (document.getElementById("maximize-window-types"));
15 |
16 | maximizeWindowTypes.addEventListener("change", async () => {
17 | await browser.storage.local.set({
18 | maximizeWindowTypes: maximizeWindowTypes.value
19 | });
20 | });
21 |
22 | document.addEventListener("DOMContentLoaded", async () => {
23 | const results = await browser.storage.local.get({
24 | maximizeWindowTypes: MaximizeWindowTypes.None
25 | });
26 | maximizeWindowTypes.value = results.maximizeWindowTypes;
27 | });
28 | }());
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 |
2 | *.cs text diff=csharp
3 | *.msbuild text
4 | *.config text
5 | *.conf text
6 | *.cscfg text
7 | *.csdef text
8 | *.xml text
9 | *.ps1 text
10 | *.DotSettings text
11 | *.sh text eol=lf
12 | *.css text
13 | *.less text
14 | *.svg text
15 | *.js text
16 | *.html text
17 | *.cshtml text
18 | _references.js -text
19 |
20 | *.csproj text eol=crlf -merge
21 | *.dbproj text eol=crlf merge=union
22 | *.fsproj text eol=crlf merge=union
23 | *.vbproj text eol=crlf merge=union
24 | *.sln text eol=crlf -merge
25 | *.bundle eol=crlf -merge
26 | packages.config -merge
27 |
28 | *.jpg binary
29 | *.jpeg binary
30 | *.png binary
31 | *.gif binary
32 |
33 | *.mdf binary
34 | *.ndf binary
35 | *.ldf binary
36 |
37 | *.doc diff=astextplain
38 | *.DOC diff=astextplain
39 | *.docx diff=astextplain
40 | *.DOCX diff=astextplain
41 | *.dot diff=astextplain
42 | *.DOT diff=astextplain
43 | *.pdf diff=astextplain
44 | *.PDF diff=astextplain
45 | *.rtf diff=astextplain
46 | *.RTF diff=astextplain
47 |
--------------------------------------------------------------------------------
/src/options.xhtml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Options
7 |
8 |
9 |
10 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | =====================
3 |
4 | Copyright (c) 2019-2020 Aaron Papp
5 |
6 | Permission is hereby granted, free of charge, to any person
7 | obtaining a copy of this software and associated documentation
8 | files (the "Software"), to deal in the Software without
9 | restriction, including without limitation the rights to use,
10 | copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the
12 | Software is furnished to do so, subject to the following
13 | conditions:
14 |
15 | The above copyright notice and this permission notice shall be
16 | included in all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 | OTHER DEALINGS IN THE SOFTWARE.
26 |
--------------------------------------------------------------------------------
/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "manifest_version": 2,
3 | "name": "Toggle Resist Fingerprinting",
4 | "version": "1.2",
5 | "description": "Adds a button to the navigation bar to toggle the \"resist fingerprinting\" setting.",
6 | "author": "Aaron Papp",
7 | "homepage_url": "https://github.com/Aaron-P/ToggleResistFingerprinting",
8 | "icons": {
9 | "24": "src/icons/icon.svg",
10 | "32": "src/icons/icon.svg",
11 | "48": "src/icons/icon.svg",
12 | "64": "src/icons/icon.svg",
13 | "96": "src/icons/icon.svg"
14 | },
15 | "permissions": [
16 | "storage",
17 | "privacy"
18 | ],
19 | "background": {
20 | "scripts": [
21 | "src/background.js"
22 | ]
23 | },
24 | "options_ui": {
25 | "browser_style": true,
26 | "page": "src/options.xhtml"
27 | },
28 | "browser_action": {
29 | "default_icon": "src/icons/icon.svg",
30 | "default_title": "Resist Fingerprinting",
31 | "default_area": "tabstrip",
32 | "theme_icons": [
33 | {
34 | "light": "src/icons/icon-light.svg",
35 | "dark": "src/icons/icon.svg",
36 | "size": 32
37 | }
38 | ]
39 | },
40 | "browser_specific_settings": {
41 | "gecko": {
42 | "id": "{3346f53a-bd1f-4f3f-94ff-70bb122083b3}",
43 | "strict_min_version": "63.0"
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/src/icons/icon.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/icons/icon-light.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/background.js:
--------------------------------------------------------------------------------
1 | (async function () {
2 | "use strict";
3 |
4 | //Bit-flag enum
5 | const MaximizeWindowTypes = {
6 | 0: "None",
7 | 1: "Normal",
8 | 2: "Private",
9 | "None": 0,
10 | "Normal": 1,
11 | "Private": 2,
12 | };
13 |
14 | async function setButtonState(enabled) {
15 | if (enabled) {
16 | await browser.browserAction.setBadgeBackgroundColor({ color: "#00BF00" });
17 | await browser.browserAction.setBadgeText({ text: "On" });
18 | } else {
19 | await browser.browserAction.setBadgeBackgroundColor({ color: "#FF0000" });
20 | await browser.browserAction.setBadgeText({ text: "Off" });
21 | }
22 | }
23 |
24 | async function refreshState() {
25 | enabled = (await browser.privacy.websites.resistFingerprinting.get({})).value;
26 | await setButtonState(enabled);
27 | }
28 |
29 | const settings = await browser.privacy.websites.resistFingerprinting.get({});
30 | let enabled = settings.value;
31 | await browser.browserAction.setBadgeTextColor({ color: "#FFFFFF" });
32 | await setButtonState(enabled);
33 |
34 | if (settings.levelOfControl !== "controlled_by_this_extension" &&
35 | settings.levelOfControl !== "controllable_by_this_extension") {
36 | await browser.browserAction.disable();
37 | await browser.browserAction.setTitle({ title: "Resist Fingerprinting (Permission Denied)" });
38 | return;
39 | }
40 |
41 | browser.browserAction.onClicked.addListener(async () => {
42 | enabled = !(await browser.privacy.websites.resistFingerprinting.get({})).value;
43 | await browser.privacy.websites.resistFingerprinting.set({ value: enabled });
44 | await setButtonState(enabled);
45 | });
46 |
47 | browser.windows.onCreated.addListener(async (window) => {
48 | //Only resize normal windows.
49 | if (window.type !== "normal")
50 | return;
51 |
52 | //If resist fingerprinting is disabled rely on normal window size functionality.
53 | refreshState();
54 | if (!enabled)
55 | return;
56 |
57 | const options = await browser.storage.local.get({
58 | maximizeWindowTypes: MaximizeWindowTypes.None
59 | });
60 |
61 | if (!window.incognito && (options.maximizeWindowTypes & MaximizeWindowTypes.Normal))
62 | await browser.windows.update(window.id, { state: "maximized" });
63 | if (window.incognito && (options.maximizeWindowTypes & MaximizeWindowTypes.Private))
64 | await browser.windows.update(window.id, { state: "maximized" });
65 | });
66 |
67 | //The setting can be changed out from under us, e.g. via about:config, and
68 | //browser.privacy.websites.resistFingerprinting.onChange doesn't seem to
69 | //fire in all cases, so check the value periodically.
70 | browser.tabs.onActivated.addListener(refreshState);
71 | browser.windows.onFocusChanged.addListener(refreshState)
72 | }());
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #################
2 | ## Eclipse
3 | #################
4 |
5 | *.pydevproject
6 | .project
7 | .metadata
8 | tmp/
9 | *.tmp
10 | *.bak
11 | *.swp
12 | *~.nib
13 | local.properties
14 | .classpath
15 | .settings/
16 | .loadpath
17 |
18 | # External tool builders
19 | .externalToolBuilders/
20 |
21 | # Locally stored "Eclipse launch configurations"
22 | *.launch
23 |
24 | # CDT-specific
25 | .cproject
26 |
27 | # PDT-specific
28 | .buildpath
29 |
30 |
31 | #################
32 | ## Visual Studio
33 | #################
34 |
35 | ## Ignore Visual Studio temporary files, build results, and
36 | ## files generated by popular Visual Studio add-ons.
37 |
38 | # User-specific files
39 | *.suo
40 | *.user
41 | *.sln.docstates
42 | *.userprefs
43 | .vagrant/
44 |
45 | # Build results
46 | [Dd]ebug/
47 | [Rr]elease/
48 | x64/
49 | build/
50 | [Bb]in/
51 | [Oo]bj/
52 |
53 | # MSTest test Results
54 | [Tt]est[Rr]esult*/
55 | [Bb]uild[Ll]og.*
56 | *.VisualState.xml
57 | TestResult.xml
58 | TestResults.xml
59 | coverage.*
60 | *.dotCover
61 | *.psess
62 | *.vsp
63 | *.vspx
64 |
65 | *_i.c
66 | *_p.c
67 | *.ilk
68 | *.meta
69 | *.obj
70 | *.pch
71 | *.pdb
72 | *.pgc
73 | *.pgd
74 | *.rsp
75 | *.sbr
76 | *.tlb
77 | *.tli
78 | *.tlh
79 | *.tmp
80 | *.tmp_proj
81 | *.log
82 | *.vspscc
83 | *.vssscc
84 | .builds
85 | *.pidb
86 | *.log
87 | *.scc
88 |
89 | # Visual C++ cache files
90 | ipch/
91 | *.aps
92 | *.ncb
93 | *.opensdf
94 | *.sdf
95 | *.cachefile
96 |
97 | # Caches
98 | _ReSharper*
99 | *.[Rr]e[Ss]harper
100 | *.ide/
101 | *.[Cc]ache
102 |
103 | # Visual Studio profiler
104 | *.psess
105 | *.vsp
106 | *.vspx
107 |
108 | # Guidance Automation Toolkit
109 | *.gpState
110 |
111 | # ReSharper is a .NET coding add-in
112 | _ReSharper*/
113 | *.[Rr]e[Ss]harper
114 |
115 | # TeamCity is a build add-in
116 | _TeamCity*
117 |
118 | # DotCover is a Code Coverage Tool
119 | *.dotCover
120 |
121 | # NCrunch
122 | *.ncrunch*
123 | .*crunch*.local.xml
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.Publish.xml
143 | #*.pubxml
144 |
145 | # NuGet Packages Directory
146 | packages/*
147 | !packages/repositories.config
148 |
149 | # Windows Azure Build Output
150 | csx
151 | *.build.csdef
152 |
153 | # Windows Store app package directory
154 | AppPackages/
155 |
156 | # Others
157 | sql/
158 | *.Cache
159 | ClientBin/
160 | [Ss]tyle[Cc]op.*
161 | ~$*
162 | *~
163 | *.dbmdl
164 | *.[Pp]ublish.xml
165 | *.pfx
166 | *.publishsettings
167 |
168 | # RIA/Silverlight projects
169 | Generated_Code/
170 |
171 | # Backup & report files from converting an old project file to a newer
172 | # Visual Studio version. Backup files are not needed, because we have git ;-)
173 | _UpgradeReport_Files/
174 | Backup*/
175 | UpgradeLog*.XML
176 | UpgradeLog*.htm
177 | *.bak
178 |
179 | # SQL Server files
180 | *.mdf
181 | *.ndf
182 | *.ldf
183 |
184 | #############
185 | ## Windows detritus
186 | #############
187 |
188 | # Windows image file caches
189 | Thumbs.db
190 | ehthumbs.db
191 |
192 | # Folder config file
193 | Desktop.ini
194 |
195 | # Recycle Bin used on file shares
196 | $RECYCLE.BIN/
197 |
198 | # Mac crap
199 | .DS_Store
200 |
201 |
202 | #############
203 | ## Python
204 | #############
205 |
206 | *.py[cod]
207 |
208 | # Packages
209 | *.egg
210 | *.egg-info
211 | dist/
212 | build/
213 | eggs/
214 | parts/
215 | var/
216 | sdist/
217 | develop-eggs/
218 | .installed.cfg
219 |
220 | # Installer logs
221 | pip-log.txt
222 |
223 | # Unit test / coverage reports
224 | .coverage
225 | .tox
226 |
227 | #Translations
228 | *.mo
229 |
230 | #Mr Developer
231 | .mr.developer.cfg
232 |
233 | #Project Specific
234 | */packages/
235 | **/$tf/*
236 | /BuildProcessTemplates/
237 | .tfignore
238 | *.nupkg
239 | *.pem
240 | **/.vs/*
241 | */7za.exe
242 | */Firefox/*
243 |
--------------------------------------------------------------------------------
/LICENSE-3RD-PARTY.md:
--------------------------------------------------------------------------------
1 | Icon made by [Freepik](https://www.freepik.com/) from Flaticon is licensed by [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/)
2 |
3 | ## Creative Commons
4 |
5 | # Attribution 3.0 Unported
6 |
7 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS LICENSE DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE INFORMATION PROVIDED, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM ITS USE.
8 |
9 | *License*
10 |
11 | THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
12 |
13 | BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
14 |
15 | ### 1. Definitions
16 |
17 | a. __"Adaptation"__ means a work based upon the Work, or upon the Work and other pre-existing works, such as a translation, adaptation, derivative work, arrangement of music or other alterations of a literary or artistic work, or phonogram or performance and includes cinematographic adaptations or any other form in which the Work may be recast, transformed, or adapted including in any form recognizably derived from the original, except that a work that constitutes a Collection will not be considered an Adaptation for the purpose of this License. For the avoidance of doubt, where the Work is a musical work, performance or phonogram, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered an Adaptation for the purpose of this License.
18 |
19 | b. __"Collection"__ means a collection of literary or artistic works, such as encyclopedias and anthologies, or performances, phonograms or broadcasts, or other works or subject matter other than works listed in Section 1(f) below, which, by reason of the selection and arrangement of their contents, constitute intellectual creations, in which the Work is included in its entirety in unmodified form along with one or more other contributions, each constituting separate and independent works in themselves, which together are assembled into a collective whole. A work that constitutes a Collection will not be considered an Adaptation (as defined above) for the purposes of this License.
20 |
21 | c. __"Distribute"__ means to make available to the public the original and copies of the Work or Adaptation, as appropriate, through sale or other transfer of ownership.
22 |
23 | d. __"Licensor"__ means the individual, individuals, entity or entities that offer(s) the Work under the terms of this License.
24 |
25 | e. __"Original Author""__ means, in the case of a literary or artistic work, the individual, individuals, entity or entities who created the Work or if no individual or entity can be identified, the publisher; and in addition (i) in the case of a performance the actors, singers, musicians, dancers, and other persons who act, sing, deliver, declaim, play in, interpret or otherwise perform literary or artistic works or expressions of folklore; (ii) in the case of a phonogram the producer being the person or legal entity who first fixes the sounds of a performance or other sounds; and, (iii) in the case of broadcasts, the organization that transmits the broadcast.
26 |
27 | f. __"Work"__ means the literary and/or artistic work offered under the terms of this License including without limitation any production in the literary, scientific and artistic domain, whatever may be the mode or form of its expression including digital form, such as a book, pamphlet and other writing; a lecture, address, sermon or other work of the same nature; a dramatic or dramatico-musical work; a choreographic work or entertainment in dumb show; a musical composition with or without words; a cinematographic work to which are assimilated works expressed by a process analogous to cinematography; a work of drawing, painting, architecture, sculpture, engraving or lithography; a photographic work to which are assimilated works expressed by a process analogous to photography; a work of applied art; an illustration, map, plan, sketch or three-dimensional work relative to geography, topography, architecture or science; a performance; a broadcast; a phonogram; a compilation of data to the extent it is protected as a copyrightable work; or a work performed by a variety or circus performer to the extent it is not otherwise considered a literary or artistic work.
28 |
29 | g. __"You"__ means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation.
30 |
31 | h. __"Publicly Perform"__ means to perform public recitations of the Work and to communicate to the public those public recitations, by any means or process, including by wire or wireless means or public digital performances; to make available to the public Works in such a way that members of the public may access these Works from a place and at a place individually chosen by them; to perform the Work to the public by any means or process and the communication to the public of the performances of the Work, including by public digital performance; to broadcast and rebroadcast the Work by any means including signs, sounds or images.
32 |
33 | i. __"Reproduce"__ means to make copies of the Work by any means including without limitation by sound or visual recordings and the right of fixation and reproducing fixations of the Work, including storage of a protected performance or phonogram in digital form or other electronic medium.
34 |
35 | ### 2. Fair Dealing Rights
36 |
37 | Nothing in this License is intended to reduce, limit, or restrict any uses free from copyright or rights arising from limitations or exceptions that are provided for in connection with the copyright protection under copyright law or other applicable laws.
38 |
39 | ### 3. License Grant
40 |
41 | Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:
42 |
43 | a. to Reproduce the Work, to incorporate the Work into one or more Collections, and to Reproduce the Work as incorporated in the Collections;
44 |
45 | b. to create and Reproduce Adaptations provided that any such Adaptation, including any translation in any medium, takes reasonable steps to clearly label, demarcate or otherwise identify that changes were made to the original Work. For example, a translation could be marked "The original work was translated from English to Spanish," or a modification could indicate "The original work has been modified.";
46 |
47 | c. to Distribute and Publicly Perform the Work including as incorporated in Collections; and,
48 |
49 | d. to Distribute and Publicly Perform Adaptations.
50 |
51 | e. For the avoidance of doubt:
52 |
53 | 1. __Non-waivable Compulsory License Schemes.__ In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme cannot be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License;
54 |
55 | 2. __Waivable Compulsory License Schemes.__ In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme can be waived, the Licensor waives the exclusive right to collect such royalties for any exercise by You of the rights granted under this License; and,
56 |
57 | 3. __Voluntary License Schemes.__ The Licensor waives the right to collect royalties, whether individually or, in the event that the Licensor is a member of a collecting society that administers voluntary licensing schemes, via that society, from any exercise by You of the rights granted under this License.
58 |
59 | The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. Subject to Section 8(f), all rights not expressly granted by Licensor are hereby reserved.
60 |
61 | ### 4. Restrictions
62 |
63 | The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:
64 |
65 | a. You may Distribute or Publicly Perform the Work only under the terms of this License. You must include a copy of, or the Uniform Resource Identifier (URI) for, this License with every copy of the Work You Distribute or Publicly Perform. You may not offer or impose any terms on the Work that restrict the terms of this License or the ability of the recipient of the Work to exercise the rights granted to that recipient under the terms of the License. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties with every copy of the Work You Distribute or Publicly Perform. When You Distribute or Publicly Perform the Work, You may not impose any effective technological measures on the Work that restrict the ability of a recipient of the Work from You to exercise the rights granted to that recipient under the terms of the License. This Section 4(a) applies to the Work as incorporated in a Collection, but this does not require the Collection apart from the Work itself to be made subject to the terms of this License. If You create a Collection, upon notice from any Licensor You must, to the extent practicable, remove from the Collection any credit as required by Section 4(b), as requested. If You create an Adaptation, upon notice from any Licensor You must, to the extent practicable, remove from the Adaptation any credit as required by Section 4(b), as requested.
66 |
67 | b. If You Distribute, or Publicly Perform the Work or any Adaptations or Collections, You must, unless a request has been made pursuant to Section 4(a), keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or if the Original Author and/or Licensor designate another party or parties (e.g., a sponsor institute, publishing entity, journal) for attribution ("Attribution Parties") in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; (ii) the title of the Work if supplied; (iii) to the extent reasonably practicable, the URI, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and (iv) , consistent with Section 3(b), in the case of an Adaptation, a credit identifying the use of the Work in the Adaptation (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). The credit required by this Section 4 (b) may be implemented in any reasonable manner; provided, however, that in the case of a Adaptation or Collection, at a minimum such credit will appear, if a credit for all contributing authors of the Adaptation or Collection appears, then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors. For the avoidance of doubt, You may only use the credit required by this Section for the purpose of attribution in the manner set out above and, by exercising Your rights under this License, You may not implicitly or explicitly assert or imply any connection with, sponsorship or endorsement by the Original Author, Licensor and/or Attribution Parties, as appropriate, of You or Your use of the Work, without the separate, express prior written permission of the Original Author, Licensor and/or Attribution Parties.
68 |
69 | c. Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable law, if You Reproduce, Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or Collections, You must not distort, mutilate, modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author's honor or reputation. Licensor agrees that in those jurisdictions (e.g. Japan), in which any exercise of the right granted in Section 3(b) of this License (the right to make Adaptations) would be deemed to be a distortion, mutilation, modification or other derogatory action prejudicial to the Original Author's honor and reputation, the Licensor will waive or not assert, as appropriate, this Section, to the fullest extent permitted by the applicable national law, to enable You to reasonably exercise Your right under Section 3(b) of this License (right to make Adaptations) but not otherwise.
70 |
71 | ### 5. Representations, Warranties and Disclaimer
72 |
73 | UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.
74 |
75 | ### 6. Limitation on Liability
76 |
77 | EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
78 |
79 | ### 7. Termination
80 |
81 | a. This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Adaptations or Collections from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License.
82 |
83 | b. Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above.
84 |
85 | ### 8. Miscellaneous
86 |
87 | a. Each time You Distribute or Publicly Perform the Work or a Collection, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License.
88 |
89 | b. Each time You Distribute or Publicly Perform an Adaptation, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License.
90 |
91 | c. If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
92 |
93 | d. No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent.
94 |
95 | e. This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You.
96 |
97 | f. The rights granted under, and the subject matter referenced, in this License were drafted utilizing the terminology of the Berne Convention for the Protection of Literary and Artistic Works (as amended on September 28, 1979), the Rome Convention of 1961, the WIPO Copyright Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996 and the Universal Copyright Convention (as revised on July 24, 1971). These rights and subject matter take effect in the relevant jurisdiction in which the License terms are sought to be enforced according to the corresponding provisions of the implementation of those treaty provisions in the applicable national law. If the standard suite of rights granted under applicable copyright law includes additional rights not granted under this License, such additional rights are deemed to be included in the License; this License is not intended to restrict the license of any rights under applicable law.
98 |
99 | > Creative Commons is not a party to this License, and makes no warranty whatsoever in connection with the Work. Creative Commons will not be liable to You or any party on any legal theory for any damages whatsoever, including without limitation any general, special, incidental or consequential damages arising in connection to this license. Notwithstanding the foregoing two (2) sentences, if Creative Commons has expressly identified itself as the Licensor hereunder, it shall have all rights and obligations of Licensor.
100 | >
101 | > Except for the limited purpose of indicating to the public that the Work is licensed under the CCPL, Creative Commons does not authorize the use by either party of the trademark "Creative Commons" or any related trademark or logo of Creative Commons without the prior written consent of Creative Commons. Any permitted use will be in compliance with Creative Commons' then-current trademark usage guidelines, as may be published on its website or otherwise made available upon request from time to time. For the avoidance of doubt, this trademark restriction does not form part of this License.
102 | >
103 | > Creative Commons may be contacted at https://creativecommons.org/.
104 |
--------------------------------------------------------------------------------
/lib/browser-polyfill.js:
--------------------------------------------------------------------------------
1 | (function (global, factory) {
2 | if (typeof define === "function" && define.amd) {
3 | define("webextension-polyfill", ["module"], factory);
4 | } else if (typeof exports !== "undefined") {
5 | factory(module);
6 | } else {
7 | var mod = {
8 | exports: {}
9 | };
10 | factory(mod);
11 | global.browser = mod.exports;
12 | }
13 | })(this, function (module) {
14 | /* webextension-polyfill - v0.5.0 - Thu Sep 26 2019 22:22:26 */
15 | /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
16 | /* vim: set sts=2 sw=2 et tw=80: */
17 | /* This Source Code Form is subject to the terms of the Mozilla Public
18 | * License, v. 2.0. If a copy of the MPL was not distributed with this
19 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
20 | "use strict";
21 |
22 | if (typeof browser === "undefined" || Object.getPrototypeOf(browser) !== Object.prototype) {
23 | const CHROME_SEND_MESSAGE_CALLBACK_NO_RESPONSE_MESSAGE = "The message port closed before a response was received.";
24 | const SEND_RESPONSE_DEPRECATION_WARNING = "Returning a Promise is the preferred way to send a reply from an onMessage/onMessageExternal listener, as the sendResponse will be removed from the specs (See https://developer.mozilla.org/docs/Mozilla/Add-ons/WebExtensions/API/runtime/onMessage)";
25 |
26 | // Wrapping the bulk of this polyfill in a one-time-use function is a minor
27 | // optimization for Firefox. Since Spidermonkey does not fully parse the
28 | // contents of a function until the first time it's called, and since it will
29 | // never actually need to be called, this allows the polyfill to be included
30 | // in Firefox nearly for free.
31 | const wrapAPIs = extensionAPIs => {
32 | // NOTE: apiMetadata is associated to the content of the api-metadata.json file
33 | // at build time by replacing the following "include" with the content of the
34 | // JSON file.
35 | const apiMetadata = {
36 | "alarms": {
37 | "clear": {
38 | "minArgs": 0,
39 | "maxArgs": 1
40 | },
41 | "clearAll": {
42 | "minArgs": 0,
43 | "maxArgs": 0
44 | },
45 | "get": {
46 | "minArgs": 0,
47 | "maxArgs": 1
48 | },
49 | "getAll": {
50 | "minArgs": 0,
51 | "maxArgs": 0
52 | }
53 | },
54 | "bookmarks": {
55 | "create": {
56 | "minArgs": 1,
57 | "maxArgs": 1
58 | },
59 | "get": {
60 | "minArgs": 1,
61 | "maxArgs": 1
62 | },
63 | "getChildren": {
64 | "minArgs": 1,
65 | "maxArgs": 1
66 | },
67 | "getRecent": {
68 | "minArgs": 1,
69 | "maxArgs": 1
70 | },
71 | "getSubTree": {
72 | "minArgs": 1,
73 | "maxArgs": 1
74 | },
75 | "getTree": {
76 | "minArgs": 0,
77 | "maxArgs": 0
78 | },
79 | "move": {
80 | "minArgs": 2,
81 | "maxArgs": 2
82 | },
83 | "remove": {
84 | "minArgs": 1,
85 | "maxArgs": 1
86 | },
87 | "removeTree": {
88 | "minArgs": 1,
89 | "maxArgs": 1
90 | },
91 | "search": {
92 | "minArgs": 1,
93 | "maxArgs": 1
94 | },
95 | "update": {
96 | "minArgs": 2,
97 | "maxArgs": 2
98 | }
99 | },
100 | "browserAction": {
101 | "disable": {
102 | "minArgs": 0,
103 | "maxArgs": 1,
104 | "fallbackToNoCallback": true
105 | },
106 | "enable": {
107 | "minArgs": 0,
108 | "maxArgs": 1,
109 | "fallbackToNoCallback": true
110 | },
111 | "getBadgeBackgroundColor": {
112 | "minArgs": 1,
113 | "maxArgs": 1
114 | },
115 | "getBadgeText": {
116 | "minArgs": 1,
117 | "maxArgs": 1
118 | },
119 | "getPopup": {
120 | "minArgs": 1,
121 | "maxArgs": 1
122 | },
123 | "getTitle": {
124 | "minArgs": 1,
125 | "maxArgs": 1
126 | },
127 | "openPopup": {
128 | "minArgs": 0,
129 | "maxArgs": 0
130 | },
131 | "setBadgeBackgroundColor": {
132 | "minArgs": 1,
133 | "maxArgs": 1,
134 | "fallbackToNoCallback": true
135 | },
136 | "setBadgeText": {
137 | "minArgs": 1,
138 | "maxArgs": 1,
139 | "fallbackToNoCallback": true
140 | },
141 | "setIcon": {
142 | "minArgs": 1,
143 | "maxArgs": 1
144 | },
145 | "setPopup": {
146 | "minArgs": 1,
147 | "maxArgs": 1,
148 | "fallbackToNoCallback": true
149 | },
150 | "setTitle": {
151 | "minArgs": 1,
152 | "maxArgs": 1,
153 | "fallbackToNoCallback": true
154 | }
155 | },
156 | "browsingData": {
157 | "remove": {
158 | "minArgs": 2,
159 | "maxArgs": 2
160 | },
161 | "removeCache": {
162 | "minArgs": 1,
163 | "maxArgs": 1
164 | },
165 | "removeCookies": {
166 | "minArgs": 1,
167 | "maxArgs": 1
168 | },
169 | "removeDownloads": {
170 | "minArgs": 1,
171 | "maxArgs": 1
172 | },
173 | "removeFormData": {
174 | "minArgs": 1,
175 | "maxArgs": 1
176 | },
177 | "removeHistory": {
178 | "minArgs": 1,
179 | "maxArgs": 1
180 | },
181 | "removeLocalStorage": {
182 | "minArgs": 1,
183 | "maxArgs": 1
184 | },
185 | "removePasswords": {
186 | "minArgs": 1,
187 | "maxArgs": 1
188 | },
189 | "removePluginData": {
190 | "minArgs": 1,
191 | "maxArgs": 1
192 | },
193 | "settings": {
194 | "minArgs": 0,
195 | "maxArgs": 0
196 | }
197 | },
198 | "commands": {
199 | "getAll": {
200 | "minArgs": 0,
201 | "maxArgs": 0
202 | }
203 | },
204 | "contextMenus": {
205 | "remove": {
206 | "minArgs": 1,
207 | "maxArgs": 1
208 | },
209 | "removeAll": {
210 | "minArgs": 0,
211 | "maxArgs": 0
212 | },
213 | "update": {
214 | "minArgs": 2,
215 | "maxArgs": 2
216 | }
217 | },
218 | "cookies": {
219 | "get": {
220 | "minArgs": 1,
221 | "maxArgs": 1
222 | },
223 | "getAll": {
224 | "minArgs": 1,
225 | "maxArgs": 1
226 | },
227 | "getAllCookieStores": {
228 | "minArgs": 0,
229 | "maxArgs": 0
230 | },
231 | "remove": {
232 | "minArgs": 1,
233 | "maxArgs": 1
234 | },
235 | "set": {
236 | "minArgs": 1,
237 | "maxArgs": 1
238 | }
239 | },
240 | "devtools": {
241 | "inspectedWindow": {
242 | "eval": {
243 | "minArgs": 1,
244 | "maxArgs": 2,
245 | "singleCallbackArg": false
246 | }
247 | },
248 | "panels": {
249 | "create": {
250 | "minArgs": 3,
251 | "maxArgs": 3,
252 | "singleCallbackArg": true
253 | }
254 | }
255 | },
256 | "downloads": {
257 | "cancel": {
258 | "minArgs": 1,
259 | "maxArgs": 1
260 | },
261 | "download": {
262 | "minArgs": 1,
263 | "maxArgs": 1
264 | },
265 | "erase": {
266 | "minArgs": 1,
267 | "maxArgs": 1
268 | },
269 | "getFileIcon": {
270 | "minArgs": 1,
271 | "maxArgs": 2
272 | },
273 | "open": {
274 | "minArgs": 1,
275 | "maxArgs": 1,
276 | "fallbackToNoCallback": true
277 | },
278 | "pause": {
279 | "minArgs": 1,
280 | "maxArgs": 1
281 | },
282 | "removeFile": {
283 | "minArgs": 1,
284 | "maxArgs": 1
285 | },
286 | "resume": {
287 | "minArgs": 1,
288 | "maxArgs": 1
289 | },
290 | "search": {
291 | "minArgs": 1,
292 | "maxArgs": 1
293 | },
294 | "show": {
295 | "minArgs": 1,
296 | "maxArgs": 1,
297 | "fallbackToNoCallback": true
298 | }
299 | },
300 | "extension": {
301 | "isAllowedFileSchemeAccess": {
302 | "minArgs": 0,
303 | "maxArgs": 0
304 | },
305 | "isAllowedIncognitoAccess": {
306 | "minArgs": 0,
307 | "maxArgs": 0
308 | }
309 | },
310 | "history": {
311 | "addUrl": {
312 | "minArgs": 1,
313 | "maxArgs": 1
314 | },
315 | "deleteAll": {
316 | "minArgs": 0,
317 | "maxArgs": 0
318 | },
319 | "deleteRange": {
320 | "minArgs": 1,
321 | "maxArgs": 1
322 | },
323 | "deleteUrl": {
324 | "minArgs": 1,
325 | "maxArgs": 1
326 | },
327 | "getVisits": {
328 | "minArgs": 1,
329 | "maxArgs": 1
330 | },
331 | "search": {
332 | "minArgs": 1,
333 | "maxArgs": 1
334 | }
335 | },
336 | "i18n": {
337 | "detectLanguage": {
338 | "minArgs": 1,
339 | "maxArgs": 1
340 | },
341 | "getAcceptLanguages": {
342 | "minArgs": 0,
343 | "maxArgs": 0
344 | }
345 | },
346 | "identity": {
347 | "launchWebAuthFlow": {
348 | "minArgs": 1,
349 | "maxArgs": 1
350 | }
351 | },
352 | "idle": {
353 | "queryState": {
354 | "minArgs": 1,
355 | "maxArgs": 1
356 | }
357 | },
358 | "management": {
359 | "get": {
360 | "minArgs": 1,
361 | "maxArgs": 1
362 | },
363 | "getAll": {
364 | "minArgs": 0,
365 | "maxArgs": 0
366 | },
367 | "getSelf": {
368 | "minArgs": 0,
369 | "maxArgs": 0
370 | },
371 | "setEnabled": {
372 | "minArgs": 2,
373 | "maxArgs": 2
374 | },
375 | "uninstallSelf": {
376 | "minArgs": 0,
377 | "maxArgs": 1
378 | }
379 | },
380 | "notifications": {
381 | "clear": {
382 | "minArgs": 1,
383 | "maxArgs": 1
384 | },
385 | "create": {
386 | "minArgs": 1,
387 | "maxArgs": 2
388 | },
389 | "getAll": {
390 | "minArgs": 0,
391 | "maxArgs": 0
392 | },
393 | "getPermissionLevel": {
394 | "minArgs": 0,
395 | "maxArgs": 0
396 | },
397 | "update": {
398 | "minArgs": 2,
399 | "maxArgs": 2
400 | }
401 | },
402 | "pageAction": {
403 | "getPopup": {
404 | "minArgs": 1,
405 | "maxArgs": 1
406 | },
407 | "getTitle": {
408 | "minArgs": 1,
409 | "maxArgs": 1
410 | },
411 | "hide": {
412 | "minArgs": 1,
413 | "maxArgs": 1,
414 | "fallbackToNoCallback": true
415 | },
416 | "setIcon": {
417 | "minArgs": 1,
418 | "maxArgs": 1
419 | },
420 | "setPopup": {
421 | "minArgs": 1,
422 | "maxArgs": 1,
423 | "fallbackToNoCallback": true
424 | },
425 | "setTitle": {
426 | "minArgs": 1,
427 | "maxArgs": 1,
428 | "fallbackToNoCallback": true
429 | },
430 | "show": {
431 | "minArgs": 1,
432 | "maxArgs": 1,
433 | "fallbackToNoCallback": true
434 | }
435 | },
436 | "permissions": {
437 | "contains": {
438 | "minArgs": 1,
439 | "maxArgs": 1
440 | },
441 | "getAll": {
442 | "minArgs": 0,
443 | "maxArgs": 0
444 | },
445 | "remove": {
446 | "minArgs": 1,
447 | "maxArgs": 1
448 | },
449 | "request": {
450 | "minArgs": 1,
451 | "maxArgs": 1
452 | }
453 | },
454 | "runtime": {
455 | "getBackgroundPage": {
456 | "minArgs": 0,
457 | "maxArgs": 0
458 | },
459 | "getPlatformInfo": {
460 | "minArgs": 0,
461 | "maxArgs": 0
462 | },
463 | "openOptionsPage": {
464 | "minArgs": 0,
465 | "maxArgs": 0
466 | },
467 | "requestUpdateCheck": {
468 | "minArgs": 0,
469 | "maxArgs": 0
470 | },
471 | "sendMessage": {
472 | "minArgs": 1,
473 | "maxArgs": 3
474 | },
475 | "sendNativeMessage": {
476 | "minArgs": 2,
477 | "maxArgs": 2
478 | },
479 | "setUninstallURL": {
480 | "minArgs": 1,
481 | "maxArgs": 1
482 | }
483 | },
484 | "sessions": {
485 | "getDevices": {
486 | "minArgs": 0,
487 | "maxArgs": 1
488 | },
489 | "getRecentlyClosed": {
490 | "minArgs": 0,
491 | "maxArgs": 1
492 | },
493 | "restore": {
494 | "minArgs": 0,
495 | "maxArgs": 1
496 | }
497 | },
498 | "storage": {
499 | "local": {
500 | "clear": {
501 | "minArgs": 0,
502 | "maxArgs": 0
503 | },
504 | "get": {
505 | "minArgs": 0,
506 | "maxArgs": 1
507 | },
508 | "getBytesInUse": {
509 | "minArgs": 0,
510 | "maxArgs": 1
511 | },
512 | "remove": {
513 | "minArgs": 1,
514 | "maxArgs": 1
515 | },
516 | "set": {
517 | "minArgs": 1,
518 | "maxArgs": 1
519 | }
520 | },
521 | "managed": {
522 | "get": {
523 | "minArgs": 0,
524 | "maxArgs": 1
525 | },
526 | "getBytesInUse": {
527 | "minArgs": 0,
528 | "maxArgs": 1
529 | }
530 | },
531 | "sync": {
532 | "clear": {
533 | "minArgs": 0,
534 | "maxArgs": 0
535 | },
536 | "get": {
537 | "minArgs": 0,
538 | "maxArgs": 1
539 | },
540 | "getBytesInUse": {
541 | "minArgs": 0,
542 | "maxArgs": 1
543 | },
544 | "remove": {
545 | "minArgs": 1,
546 | "maxArgs": 1
547 | },
548 | "set": {
549 | "minArgs": 1,
550 | "maxArgs": 1
551 | }
552 | }
553 | },
554 | "tabs": {
555 | "captureVisibleTab": {
556 | "minArgs": 0,
557 | "maxArgs": 2
558 | },
559 | "create": {
560 | "minArgs": 1,
561 | "maxArgs": 1
562 | },
563 | "detectLanguage": {
564 | "minArgs": 0,
565 | "maxArgs": 1
566 | },
567 | "discard": {
568 | "minArgs": 0,
569 | "maxArgs": 1
570 | },
571 | "duplicate": {
572 | "minArgs": 1,
573 | "maxArgs": 1
574 | },
575 | "executeScript": {
576 | "minArgs": 1,
577 | "maxArgs": 2
578 | },
579 | "get": {
580 | "minArgs": 1,
581 | "maxArgs": 1
582 | },
583 | "getCurrent": {
584 | "minArgs": 0,
585 | "maxArgs": 0
586 | },
587 | "getZoom": {
588 | "minArgs": 0,
589 | "maxArgs": 1
590 | },
591 | "getZoomSettings": {
592 | "minArgs": 0,
593 | "maxArgs": 1
594 | },
595 | "highlight": {
596 | "minArgs": 1,
597 | "maxArgs": 1
598 | },
599 | "insertCSS": {
600 | "minArgs": 1,
601 | "maxArgs": 2
602 | },
603 | "move": {
604 | "minArgs": 2,
605 | "maxArgs": 2
606 | },
607 | "query": {
608 | "minArgs": 1,
609 | "maxArgs": 1
610 | },
611 | "reload": {
612 | "minArgs": 0,
613 | "maxArgs": 2
614 | },
615 | "remove": {
616 | "minArgs": 1,
617 | "maxArgs": 1
618 | },
619 | "removeCSS": {
620 | "minArgs": 1,
621 | "maxArgs": 2
622 | },
623 | "sendMessage": {
624 | "minArgs": 2,
625 | "maxArgs": 3
626 | },
627 | "setZoom": {
628 | "minArgs": 1,
629 | "maxArgs": 2
630 | },
631 | "setZoomSettings": {
632 | "minArgs": 1,
633 | "maxArgs": 2
634 | },
635 | "update": {
636 | "minArgs": 1,
637 | "maxArgs": 2
638 | }
639 | },
640 | "topSites": {
641 | "get": {
642 | "minArgs": 0,
643 | "maxArgs": 0
644 | }
645 | },
646 | "webNavigation": {
647 | "getAllFrames": {
648 | "minArgs": 1,
649 | "maxArgs": 1
650 | },
651 | "getFrame": {
652 | "minArgs": 1,
653 | "maxArgs": 1
654 | }
655 | },
656 | "webRequest": {
657 | "handlerBehaviorChanged": {
658 | "minArgs": 0,
659 | "maxArgs": 0
660 | }
661 | },
662 | "windows": {
663 | "create": {
664 | "minArgs": 0,
665 | "maxArgs": 1
666 | },
667 | "get": {
668 | "minArgs": 1,
669 | "maxArgs": 2
670 | },
671 | "getAll": {
672 | "minArgs": 0,
673 | "maxArgs": 1
674 | },
675 | "getCurrent": {
676 | "minArgs": 0,
677 | "maxArgs": 1
678 | },
679 | "getLastFocused": {
680 | "minArgs": 0,
681 | "maxArgs": 1
682 | },
683 | "remove": {
684 | "minArgs": 1,
685 | "maxArgs": 1
686 | },
687 | "update": {
688 | "minArgs": 2,
689 | "maxArgs": 2
690 | }
691 | }
692 | };
693 |
694 | if (Object.keys(apiMetadata).length === 0) {
695 | throw new Error("api-metadata.json has not been included in browser-polyfill");
696 | }
697 |
698 | /**
699 | * A WeakMap subclass which creates and stores a value for any key which does
700 | * not exist when accessed, but behaves exactly as an ordinary WeakMap
701 | * otherwise.
702 | *
703 | * @param {function} createItem
704 | * A function which will be called in order to create the value for any
705 | * key which does not exist, the first time it is accessed. The
706 | * function receives, as its only argument, the key being created.
707 | */
708 | class DefaultWeakMap extends WeakMap {
709 | constructor(createItem, items = undefined) {
710 | super(items);
711 | this.createItem = createItem;
712 | }
713 |
714 | get(key) {
715 | if (!this.has(key)) {
716 | this.set(key, this.createItem(key));
717 | }
718 |
719 | return super.get(key);
720 | }
721 | }
722 |
723 | /**
724 | * Returns true if the given object is an object with a `then` method, and can
725 | * therefore be assumed to behave as a Promise.
726 | *
727 | * @param {*} value The value to test.
728 | * @returns {boolean} True if the value is thenable.
729 | */
730 | const isThenable = value => {
731 | return value && typeof value === "object" && typeof value.then === "function";
732 | };
733 |
734 | /**
735 | * Creates and returns a function which, when called, will resolve or reject
736 | * the given promise based on how it is called:
737 | *
738 | * - If, when called, `chrome.runtime.lastError` contains a non-null object,
739 | * the promise is rejected with that value.
740 | * - If the function is called with exactly one argument, the promise is
741 | * resolved to that value.
742 | * - Otherwise, the promise is resolved to an array containing all of the
743 | * function's arguments.
744 | *
745 | * @param {object} promise
746 | * An object containing the resolution and rejection functions of a
747 | * promise.
748 | * @param {function} promise.resolve
749 | * The promise's resolution function.
750 | * @param {function} promise.rejection
751 | * The promise's rejection function.
752 | * @param {object} metadata
753 | * Metadata about the wrapped method which has created the callback.
754 | * @param {integer} metadata.maxResolvedArgs
755 | * The maximum number of arguments which may be passed to the
756 | * callback created by the wrapped async function.
757 | *
758 | * @returns {function}
759 | * The generated callback function.
760 | */
761 | const makeCallback = (promise, metadata) => {
762 | return (...callbackArgs) => {
763 | if (extensionAPIs.runtime.lastError) {
764 | promise.reject(extensionAPIs.runtime.lastError);
765 | } else if (metadata.singleCallbackArg || callbackArgs.length <= 1 && metadata.singleCallbackArg !== false) {
766 | promise.resolve(callbackArgs[0]);
767 | } else {
768 | promise.resolve(callbackArgs);
769 | }
770 | };
771 | };
772 |
773 | const pluralizeArguments = numArgs => numArgs == 1 ? "argument" : "arguments";
774 |
775 | /**
776 | * Creates a wrapper function for a method with the given name and metadata.
777 | *
778 | * @param {string} name
779 | * The name of the method which is being wrapped.
780 | * @param {object} metadata
781 | * Metadata about the method being wrapped.
782 | * @param {integer} metadata.minArgs
783 | * The minimum number of arguments which must be passed to the
784 | * function. If called with fewer than this number of arguments, the
785 | * wrapper will raise an exception.
786 | * @param {integer} metadata.maxArgs
787 | * The maximum number of arguments which may be passed to the
788 | * function. If called with more than this number of arguments, the
789 | * wrapper will raise an exception.
790 | * @param {integer} metadata.maxResolvedArgs
791 | * The maximum number of arguments which may be passed to the
792 | * callback created by the wrapped async function.
793 | *
794 | * @returns {function(object, ...*)}
795 | * The generated wrapper function.
796 | */
797 | const wrapAsyncFunction = (name, metadata) => {
798 | return function asyncFunctionWrapper(target, ...args) {
799 | if (args.length < metadata.minArgs) {
800 | throw new Error(`Expected at least ${metadata.minArgs} ${pluralizeArguments(metadata.minArgs)} for ${name}(), got ${args.length}`);
801 | }
802 |
803 | if (args.length > metadata.maxArgs) {
804 | throw new Error(`Expected at most ${metadata.maxArgs} ${pluralizeArguments(metadata.maxArgs)} for ${name}(), got ${args.length}`);
805 | }
806 |
807 | return new Promise((resolve, reject) => {
808 | if (metadata.fallbackToNoCallback) {
809 | // This API method has currently no callback on Chrome, but it return a promise on Firefox,
810 | // and so the polyfill will try to call it with a callback first, and it will fallback
811 | // to not passing the callback if the first call fails.
812 | try {
813 | target[name](...args, makeCallback({ resolve, reject }, metadata));
814 | } catch (cbError) {
815 | console.warn(`${name} API method doesn't seem to support the callback parameter, ` + "falling back to call it without a callback: ", cbError);
816 |
817 | target[name](...args);
818 |
819 | // Update the API method metadata, so that the next API calls will not try to
820 | // use the unsupported callback anymore.
821 | metadata.fallbackToNoCallback = false;
822 | metadata.noCallback = true;
823 |
824 | resolve();
825 | }
826 | } else if (metadata.noCallback) {
827 | target[name](...args);
828 | resolve();
829 | } else {
830 | target[name](...args, makeCallback({ resolve, reject }, metadata));
831 | }
832 | });
833 | };
834 | };
835 |
836 | /**
837 | * Wraps an existing method of the target object, so that calls to it are
838 | * intercepted by the given wrapper function. The wrapper function receives,
839 | * as its first argument, the original `target` object, followed by each of
840 | * the arguments passed to the original method.
841 | *
842 | * @param {object} target
843 | * The original target object that the wrapped method belongs to.
844 | * @param {function} method
845 | * The method being wrapped. This is used as the target of the Proxy
846 | * object which is created to wrap the method.
847 | * @param {function} wrapper
848 | * The wrapper function which is called in place of a direct invocation
849 | * of the wrapped method.
850 | *
851 | * @returns {Proxy}
852 | * A Proxy object for the given method, which invokes the given wrapper
853 | * method in its place.
854 | */
855 | const wrapMethod = (target, method, wrapper) => {
856 | return new Proxy(method, {
857 | apply(targetMethod, thisObj, args) {
858 | return wrapper.call(thisObj, target, ...args);
859 | }
860 | });
861 | };
862 |
863 | let hasOwnProperty = Function.call.bind(Object.prototype.hasOwnProperty);
864 |
865 | /**
866 | * Wraps an object in a Proxy which intercepts and wraps certain methods
867 | * based on the given `wrappers` and `metadata` objects.
868 | *
869 | * @param {object} target
870 | * The target object to wrap.
871 | *
872 | * @param {object} [wrappers = {}]
873 | * An object tree containing wrapper functions for special cases. Any
874 | * function present in this object tree is called in place of the
875 | * method in the same location in the `target` object tree. These
876 | * wrapper methods are invoked as described in {@see wrapMethod}.
877 | *
878 | * @param {object} [metadata = {}]
879 | * An object tree containing metadata used to automatically generate
880 | * Promise-based wrapper functions for asynchronous. Any function in
881 | * the `target` object tree which has a corresponding metadata object
882 | * in the same location in the `metadata` tree is replaced with an
883 | * automatically-generated wrapper function, as described in
884 | * {@see wrapAsyncFunction}
885 | *
886 | * @returns {Proxy