├── .gitignore
├── extension
├── APV3_Icon_2d_2c_16.png
├── APV3_Icon_2d_2c_24.png
├── APV3_Icon_2d_2c_32.png
├── APV3_Icon_2d_2c_48.png
├── APV3_Icon_2d_2c_64.png
├── APV3_Icon_2d_2c_96.png
├── APV3_Icon_2d_2c_128.png
├── manifest.json
├── worker.js
├── popup.html
├── content.js
├── popup.css
├── main.js
└── popup.js
├── resources
├── WebRTC
│ ├── audio
│ │ └── audio.mp3
│ ├── images
│ │ └── poster.jpg
│ ├── video
│ │ ├── chrome.mp4
│ │ ├── chrome.ogv
│ │ └── chrome.webm
│ ├── _
│ │ ├── images
│ │ │ └── webrtc-icon-192x192.png
│ │ └── css
│ │ │ ├── main.css
│ │ │ └── fonts.css
│ └── css
│ │ └── main.css
├── Icons
│ ├── APV3_Icon_2d_2c_128.png
│ ├── APV3_Icon_2d_2c_16.png
│ ├── APV3_Icon_2d_2c_192.png
│ ├── APV3_Icon_2d_2c_24.png
│ ├── APV3_Icon_2d_2c_256.png
│ ├── APV3_Icon_2d_2c_32.png
│ ├── APV3_Icon_2d_2c_48.png
│ ├── APV3_Icon_2d_2c_512.png
│ ├── APV3_Icon_2d_2c_64.png
│ └── APV3_Icon_2d_2c_96.png
├── index.js
├── index.css
└── index.html
├── .editorconfig
├── FAQ.md
├── CHANGELOG.md
├── README.md
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 | *.zip
2 | *.pem
3 |
4 | # temporary folders
5 | extension.*
6 | resources.*
7 |
--------------------------------------------------------------------------------
/extension/APV3_Icon_2d_2c_16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/extension/APV3_Icon_2d_2c_16.png
--------------------------------------------------------------------------------
/extension/APV3_Icon_2d_2c_24.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/extension/APV3_Icon_2d_2c_24.png
--------------------------------------------------------------------------------
/extension/APV3_Icon_2d_2c_32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/extension/APV3_Icon_2d_2c_32.png
--------------------------------------------------------------------------------
/extension/APV3_Icon_2d_2c_48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/extension/APV3_Icon_2d_2c_48.png
--------------------------------------------------------------------------------
/extension/APV3_Icon_2d_2c_64.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/extension/APV3_Icon_2d_2c_64.png
--------------------------------------------------------------------------------
/extension/APV3_Icon_2d_2c_96.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/extension/APV3_Icon_2d_2c_96.png
--------------------------------------------------------------------------------
/resources/WebRTC/audio/audio.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/resources/WebRTC/audio/audio.mp3
--------------------------------------------------------------------------------
/extension/APV3_Icon_2d_2c_128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/extension/APV3_Icon_2d_2c_128.png
--------------------------------------------------------------------------------
/resources/WebRTC/images/poster.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/resources/WebRTC/images/poster.jpg
--------------------------------------------------------------------------------
/resources/WebRTC/video/chrome.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/resources/WebRTC/video/chrome.mp4
--------------------------------------------------------------------------------
/resources/WebRTC/video/chrome.ogv:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/resources/WebRTC/video/chrome.ogv
--------------------------------------------------------------------------------
/resources/WebRTC/video/chrome.webm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/resources/WebRTC/video/chrome.webm
--------------------------------------------------------------------------------
/resources/Icons/APV3_Icon_2d_2c_128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/resources/Icons/APV3_Icon_2d_2c_128.png
--------------------------------------------------------------------------------
/resources/Icons/APV3_Icon_2d_2c_16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/resources/Icons/APV3_Icon_2d_2c_16.png
--------------------------------------------------------------------------------
/resources/Icons/APV3_Icon_2d_2c_192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/resources/Icons/APV3_Icon_2d_2c_192.png
--------------------------------------------------------------------------------
/resources/Icons/APV3_Icon_2d_2c_24.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/resources/Icons/APV3_Icon_2d_2c_24.png
--------------------------------------------------------------------------------
/resources/Icons/APV3_Icon_2d_2c_256.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/resources/Icons/APV3_Icon_2d_2c_256.png
--------------------------------------------------------------------------------
/resources/Icons/APV3_Icon_2d_2c_32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/resources/Icons/APV3_Icon_2d_2c_32.png
--------------------------------------------------------------------------------
/resources/Icons/APV3_Icon_2d_2c_48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/resources/Icons/APV3_Icon_2d_2c_48.png
--------------------------------------------------------------------------------
/resources/Icons/APV3_Icon_2d_2c_512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/resources/Icons/APV3_Icon_2d_2c_512.png
--------------------------------------------------------------------------------
/resources/Icons/APV3_Icon_2d_2c_64.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/resources/Icons/APV3_Icon_2d_2c_64.png
--------------------------------------------------------------------------------
/resources/Icons/APV3_Icon_2d_2c_96.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/resources/Icons/APV3_Icon_2d_2c_96.png
--------------------------------------------------------------------------------
/resources/WebRTC/_/images/webrtc-icon-192x192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rain-fighters/AudioPick/HEAD/resources/WebRTC/_/images/webrtc-icon-192x192.png
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # top-most EditorConfig file
2 | root = true
3 |
4 | # all files
5 | [*]
6 | charset = utf-8
7 | end_of_line = lf
8 | indent_style = tab
9 | indent_size = 4
10 |
--------------------------------------------------------------------------------
/resources/WebRTC/css/main.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree.
7 | */
8 |
9 | audio {
10 | margin: 0 0 1.5em 0;
11 | width: 100%;
12 | }
13 |
14 | div#sources > div {
15 | float: left;
16 | margin: 0 1em 0 0;
17 | width: calc(50% - 0.5em);
18 | }
19 |
20 | div#sources > div:last-of-type {
21 | margin: 0;
22 | }
23 |
24 | select {
25 | margin: 0 0 0.5em 0;
26 | }
27 |
28 | video {
29 | background: black;
30 | height: 234px;
31 | }
32 |
--------------------------------------------------------------------------------
/extension/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "manifest_version": 3,
3 | "name": "AudioPick",
4 | "short_name": "AudioPick",
5 | "description": "Pick a preferred audio output device for HTML5 audio and video elements",
6 | "author": "necropola@rain-fighters.net",
7 | "homepage_url": "https://rain-fighters.github.io/AudioPick/",
8 | "version": "0.3.11",
9 | "version_name": "0.3.11",
10 | "action": {
11 | "default_icon": {
12 | "16": "APV3_Icon_2d_2c_16.png",
13 | "32": "APV3_Icon_2d_2c_32.png",
14 | "48": "APV3_Icon_2d_2c_48.png",
15 | "128": "APV3_Icon_2d_2c_128.png"
16 | },
17 | "default_title": "AudioPick",
18 | "default_popup": "popup.html"
19 | },
20 | "icons": {
21 | "16": "APV3_Icon_2d_2c_16.png",
22 | "32": "APV3_Icon_2d_2c_32.png",
23 | "48": "APV3_Icon_2d_2c_48.png",
24 | "128": "APV3_Icon_2d_2c_128.png"
25 | },
26 | "host_permissions": ["https://*/*"],
27 | "background": {
28 | "service_worker": "worker.js"
29 | },
30 | "content_scripts": [
31 | {
32 | "matches": ["https://*/*"],
33 | "js": ["main.js"],
34 | "world": "MAIN",
35 | "all_frames" : false
36 | },
37 | {
38 | "matches": ["https://*/*"],
39 | "js": ["content.js"],
40 | "world": "ISOLATED",
41 | "all_frames" : false
42 | }
43 | ],
44 | "permissions": [
45 | "contentSettings",
46 | "storage",
47 | "scripting",
48 | "activeTab",
49 | "favicon"
50 | ]
51 | }
52 |
--------------------------------------------------------------------------------
/FAQ.md:
--------------------------------------------------------------------------------
1 | # FAQ
2 | Work in progress ...
3 |
4 | - TOC
5 | {:toc}
6 |
7 | ### Why does the extension need **Microphone Access**?
8 | ...
9 |
10 | ### Are there **Conflicts** between the extension and sites which manage audio devices on their own, e. g. **Discord**, **Teams**, **Signal**, **Elements**, ...?
11 | ...
12 |
13 | ### Which **Platforms** are supported by the extension?
14 | ...
15 |
16 | ### Which **Sites** are supported by the extension?
17 | Generally only **HTTPS** sites are supported. This excludes internal chrome browser pages like `chrome://settings` as well as sites not offering **SSL** encryption. The latter is rather rare nowadays and usually means that the site is either misconfigured or should not be trusted anyway.
18 |
19 | Another case are sites which (somehow) disable extensions entirely, e. g. the **Chrome WebStore** (`https://chromewebstore.google.com`), or sites which explicitly deny microphone access by sending a `Feature-Policy` or `Permissions-Policy` **Response Header** stating so, e. g. `https://stackoverflow.com`.
20 |
21 | All of these cases are indicated by an Error Message in the footer of the extension popup.
22 |
23 | Other sites should work as long as they are using **HTML5** elements of type `HTMLMediaElement` or `AudioContext` to play audio and we have been smart enough to find them and inject our `changeSinkId` listener. The following table is the result of testing various popoular sites with **AudioPick-0.3.9** on **Chrome 120 (64-bit) / Windows 10** – current as of **January 2024**.
24 |
25 | | Site | Status | Comment |
26 | |------|--------|---------|
27 | | **YouTube** `https://www.youtube.com` | Fully Working | No known issues. |
28 | | **Twitch** `https://www.twitch.tv` | Fully Working | No known issues. |
29 | | **YouTube Music** `https://music.youtube.com` | Fully Working | No known issues. |
30 | | **Spotify** `https://open.spotify.com` | Fully Working | No known issues. |
31 | | **SoundCloud** `https://soundcloud.com`| Mostly Working | Might require a page reload when a new tab is opened through a link/bookmark to a specific track and autoplay starts before **AudioPick** is able to inject its `changeSinkId` listener properly. |
32 | | **Deezer** `https://www.deezer.com` | Kinda Working | Requires to click `Play->Pause->Play` once after (re-)loading the page in order to help **AudioPick** to inject its `changeSinkId` listener properly. |
33 | | **Amazon Music** `https://music.amazon.com` | Probably Working | The demo podcasts worked (without needing a subscription). |
34 | | **Netflix** `https://www.netflix.com` | Fully Working | No known issues. |
35 | | **Disney+** `https://www.disneyplus.com` | Maybe Working | Don't have a subscription and hence cannot test. Reports from other **AudioPick** users via [GitHub Issue](https://github.com/rain-fighters/AudioPick/issues) welcome. |
36 |
37 | ### Why isn't the extension available for **Other Browsers**, e. g. **Firefox**?
38 | ...
39 |
40 | ### Where do I report **Issues** with the extension?
41 | ...
42 |
43 | ### How did you come up with the **Idea** for the extension?
44 | ...
45 |
46 | ### How can I **Support AudioPick**?
47 | ...
48 |
49 | ### What is or rather who are **Rain-Fighters**?
50 | ...
51 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # CHANGELOG
2 |
3 | ### AudioPick-0.3.10
4 | - Improve debug logging, e. g. inject `enableDebug` into content scripts running in world **MAIN**.
5 | - Fully support **Deezer** and **SoundCloud**.
6 | - Add a `smartMicAccess` mode (enabled via checkbox in the Popup) which significantly reduces microphone permissions granted by the extension.
7 | - Add an info message to the popup header.
8 | - Add a **site info heading** with `favicon`, `host/domain` and `micPolicy`.
9 | - No longer offer the `communications` device to be picked.
10 | - Improve `default` device label on Windows (and possibly MacOS).
11 | - Improve demo page (`resources/index.*`), e. g. add an `AudioContext` and a video in `iframe` example.
12 | - Fix/enhance communication with sub-frames, but disable injecting
13 | into all_frames for now, since changing sinkIds in sub-frames only works on same-origin or when the `iframe` specifies `allow="microphone"`.
14 |
15 | ### AudioPick-0.3.9
16 | - Add a Popup / UI option to enable/disable content script debug messages.
17 | - Detect and respect site Permissions-Policy for microphone access,
18 | e. g. on https://stackoverflow.com
19 | - Work around a Chrome on linux bug/issue where the service worker does
20 | not wake up (fast enough) from inactive state on message events.
21 |
22 | ### AudioPick-0.3.8
23 | - Rewrite for Manifest V3
24 | - New enhanced Popup / UI with dark/light mode support
25 | - New icon / logo
26 | - Allow to store (star) a preferred audio device per domain
27 | - Remove option to set a global preferred device for the browser
28 | - Inject a content script into `world:MAIN` in order to find
29 | media elements which havent't been inserted into the DOM tree,
30 | i. e. sites like **Spotify** and **SoundCloud** should now work, too.
31 | - Minimize the number of **microphone permissions** added/managed by the extension
32 | - by resetting the permission back to **ask** when the default device has been
33 | chosen again for a tab/domain
34 | - by not having a global preferred device for the browser anymore
35 |
36 | ### AudioPick-0.2.2 - 2016-05-21
37 | - going stable
38 | - revert `page_action back` to `browser_action`
39 | - code cleanup
40 |
41 | ### AudioPick-0.2.1 - 2016-05-18
42 | - quick fix to prevent a loop caused by the *observer*
43 |
44 | ### AudioPick-0.2.0 - 2016-05-18
45 | - substitute calls to `getUserMedia()` by `get_help_with_GUM`, i. e. write directly to `contentSettings['microphone']` thereby allowing the modification of audio/video on unencrypted pages
46 | - code cleanup + better diagnostic output
47 | - fixes to handling of asynchronous actions, especially promises
48 | - overwrite devices for an entire frame set, i. e. when sub frames ask the background page for the `default_no`, it asks the top frame and passes this information back to the sub frame
49 | - popup only ever asks the top frame for its current `sink_no`
50 |
51 | ### AudioPick-0.1.4 - 2016-05-17
52 | - add `'use strict'` to all scripts
53 | - inject the content script into all frames so that `setSinkId()` now also works for embedded audio/video (over HTTPS)
54 | - only call `getUserMedia()` on a site (once) when a call to `setSinkId` actually fails. This should greatly reduce the number of sites added to the list of microphone exceptions.
55 | - change `browser_action` into `page_action`
56 | - immediately commit changes to the popup device list (commit button removed)
57 | - remember the last temporary `sink_no` choice of a content page when creating the popup device list for it
58 |
--------------------------------------------------------------------------------
/resources/index.js:
--------------------------------------------------------------------------------
1 | var visible_shadow_audio;
2 | var hidden_audio = new Audio("./WebRTC/audio/audio.mp3");
3 | var visible_audioContext_source;
4 | var hidden_audioContext;
5 |
6 | function play_dom_audio() {
7 | var dom_audio = document.getElementById("dom_audio")
8 | if (dom_audio.paused)
9 | {
10 | dom_audio.loop = true;
11 | dom_audio.play();
12 | } else {
13 | dom_audio.pause();
14 | }
15 | }
16 |
17 | function play_hidden_audio() {
18 | if (hidden_audio) {
19 | if (hidden_audio.paused)
20 | {
21 | hidden_audio.loop = true;
22 | hidden_audio.play();
23 | } else {
24 | hidden_audio.pause();
25 | }
26 | }
27 | }
28 |
29 | function add_visible_audio() {
30 | let audio = document.getElementById("visible_audio");
31 | if (audio) {
32 | if (audio.paused)
33 | {
34 | audio.loop = true;
35 | audio.play();
36 | } else {
37 | audio.pause();
38 | }
39 | } else {
40 | audio = new Audio("./WebRTC/audio/audio.mp3");
41 | audio.id = "visible_audio";
42 | audio.controls = true;
43 | document.getElementById("div_visible_audio").appendChild(audio);
44 | document.getElementById("add_visible_audio").innerText = "Play/Pause new Visible";
45 | }
46 | }
47 |
48 | function add_visible_shadow_audio() {
49 | if (visible_shadow_audio) {
50 | if (visible_shadow_audio.paused)
51 | {
52 | visible_shadow_audio.loop = true;
53 | visible_shadow_audio.play();
54 | } else {
55 | visible_shadow_audio.pause();
56 | }
57 | } else {
58 | var s = document.getElementById("div_visible_shadow_audio").attachShadow({ mode: "closed" });
59 | visible_shadow_audio = new Audio("./WebRTC/audio/audio.mp3");
60 | visible_shadow_audio.id = "visible_shadow_audio";
61 | visible_shadow_audio.controls = true;
62 | s.appendChild(visible_shadow_audio);
63 | document.getElementById("add_visible_shadow_audio").innerText = "Play/Pause shadowRoot";
64 | }
65 | }
66 |
67 | function add_visible_audioContext_source() {
68 | if (visible_audioContext_source) {
69 | if (visible_audioContext_source.paused)
70 | {
71 | visible_audioContext_source.loop = true;
72 | visible_audioContext_source.play();
73 | } else {
74 | visible_audioContext_source.pause();
75 | }
76 | } else {
77 | visible_audioContext_source = new Audio("./WebRTC/audio/audio.mp3");
78 | visible_audioContext_source.id = "visible_audioContext_source";
79 | visible_audioContext_source.controls = true;
80 | document.getElementById("div_visible_audioContext_source").appendChild(visible_audioContext_source);
81 | document.getElementById("add_visible_audioContext_source").innerText = "Play/Pause visible AudioContext Source";
82 | document.getElementById("add_hidden_audioContext").disabled = false;
83 | }
84 | }
85 |
86 | function add_hidden_audioContext() {
87 | if (hidden_audioContext) {
88 | if (visible_audioContext_source.paused)
89 | {
90 | visible_audioContext_source.loop = true;
91 | visible_audioContext_source.play();
92 | } else {
93 | visible_audioContext_source.pause();
94 | }
95 | } else {
96 | hidden_audioContext = new AudioContext;
97 | const source = hidden_audioContext.createMediaElementSource(visible_audioContext_source);
98 | const gainNode = hidden_audioContext.createGain();
99 | source.connect(gainNode);
100 | gainNode.connect(hidden_audioContext.destination);
101 | document.getElementById("add_hidden_audioContext").innerText = "Play/Pause hidden AudioContext (Source)";
102 | document.getElementById("div_hidden_audioContext").innerText = "Sink is now determined by AudioContext!";
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/extension/worker.js:
--------------------------------------------------------------------------------
1 | // Worker script handles:
2 | // 1) Providing microphone access to our content script for basic function.
3 | // 2) Relaying messages from any frames/iframes/children back to the main tab.
4 | // 3) Injecting sinkId changes into WORLD:MAIN.
5 | // Worker runs in BACKGROUND.
6 | //
7 | // Prefix used for our local storage variables.
8 | const storagePrefix = "preferredDevice_";
9 |
10 | function onMessage(request, sender, sendResponse) {
11 | switch (request.action) {
12 | case "getActiveDeviceBG":
13 | // Create a proxy response function to catch errors that can happen
14 | // when the top content scripts is not (yet) resposnding.
15 | const responder = function (...args) {
16 | if (args.length === 0) {
17 | if (chrome.runtime.lastError) {
18 | // Do nothing.
19 | // We just need to read this lastError value to
20 | // prevent an error being logged to the console.
21 | }
22 | // The top content script is not (yet) responding
23 | sendResponse(null);
24 | } else {
25 | sendResponse.apply(this, args);
26 | }
27 | }
28 | // Relay the message to the top (frameId: 0) content script.
29 | chrome.tabs.sendMessage(sender.tab.id,
30 | {action: "getActiveDevice"}, {frameId: 0}, responder);
31 | // We need to return true from onMessage() to keep the channel open,
32 | // since our sendReponse() is called asynchronously here.
33 | return true;
34 | case "setMicAccess":
35 | // Set the current microphone access permissions for the tab.
36 | // Request format: {value: "allow"}
37 | chrome.contentSettings.microphone.set({
38 | primaryPattern: sender.tab.url.split("/")[0] + "//" +
39 | sender.tab.url.split("/")[2] + "/*",
40 | scope: (
41 | sender.tab.incognito
42 | ? "incognito_session_only"
43 | : "regular"
44 | ),
45 | setting: request.value
46 | }).then(function() {
47 | sendResponse(true);
48 | }).catch(function() {
49 | sendResponse(false);
50 | });
51 | return true;
52 | case "injectSink":
53 | // Inject the passed sinkId (request.value) into MAIN.
54 | // Then dispatch a "changeSinkId" event to update all elements.
55 | //
56 | // NOTE that target: {allFrames: true} does not make sense, simce
57 | // 1. we only want to target frames where we actually injected our
58 | // content scripts and
59 | // 2. (even more importantly) sinkIds are unique per frame, i. e.
60 | // the same device has a different deviceId in top and in sub.
61 | // Basically the content scripts for top and sub-frames need to
62 | // independently calculate and pass the correct sinkId for their
63 | // window/frame and the worker needs to explicitely target the
64 | // sender's frameId(s).
65 | chrome.scripting.executeScript({
66 | args: [request.value],
67 | func: function (activeSinkId) {
68 | window.APV3_UN1QU3_activeSinkId = activeSinkId;
69 | window.dispatchEvent(
70 | new CustomEvent(
71 | "changeSinkId",
72 | {detail: activeSinkId}
73 | )
74 | );
75 | },
76 | target: {tabId: sender.tab.id, frameIds: [sender.frameId], allFrames : false},
77 | world: "MAIN"
78 | });
79 | break;
80 | case "injectDebug":
81 | chrome.scripting.executeScript({
82 | args: [request.value],
83 | func: function (enableDebug) {
84 | window.APV3_UN1QU3_enableDebug = enableDebug;
85 | },
86 | target: {tabId: sender.tab.id, frameIds: [sender.frameId], allFrames : false},
87 | world: "MAIN"
88 | });
89 | break;
90 | case "wakeup":
91 | // A dumnmy message that we are being sent to wake us up.
92 | // This is a hack/workaround for a chrome bug on linux.
93 | break;
94 | }
95 | }
96 |
97 | // Start listening immediately.
98 | chrome.runtime.onMessage.addListener(onMessage);
99 |
--------------------------------------------------------------------------------
/extension/popup.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
114 |
115 |
116 |
117 |
118 |
146 |
147 |
148 |
--------------------------------------------------------------------------------
/extension/content.js:
--------------------------------------------------------------------------------
1 | // Content script handles:
2 | // 1) Loading and applying saved devices.
3 | // 2) Listening for device change messages from popup/worker.
4 | // Content script runs in WORLD:ISOLATED.
5 |
6 | // Prefix used for our local storage variables.
7 | const storagePrefix = "preferredDevice_";
8 |
9 | // Assume active device is system default until proven otherwise.
10 | var activeDevice = "default";
11 | var activeSinkId;
12 |
13 | // Write to console.log, if debugging is enabled.
14 | function debugMessage(...args) {
15 | chrome.storage.local.get(["enableDebug"]).then(function(result) {
16 | if (result && result.enableDebug) {
17 | console.log('APV3-content.js (' +
18 | ((window === top) ? 'top-origin: ' : 'sub-origin: ') +
19 | window.location.origin + ')', ...args);
20 | }
21 | });
22 | }
23 |
24 | // Inject the enableDebug value into MAIN (all_frames) via worker
25 | async function injectDebug(enableDebug) {
26 | await chrome.runtime.sendMessage({
27 | action: "injectDebug",
28 | value: enableDebug
29 | });
30 | }
31 |
32 | // Messages are expected in the format {action: value, ...}
33 | function onMessage(request, sender, sendResponse) {
34 | switch (request.action) {
35 | case "updateDebug":
36 | // The extension popup has changed chrome.storage.local["enableDebug"].
37 | injectDebug(request.value);
38 | break;
39 | case "setActiveDevice":
40 | // The extension popup is asking us (top and children) to set a new active device.
41 | debugMessage("| onMessage: setActiveDevice | sendAudioDevice:", request.device);
42 | setAudioDevice(request.device);
43 | break;
44 | case "getActiveDevice":
45 | // The exension popup or a child of this tab (via worker)
46 | // is asking for the activeDevice.
47 | if (window === top) { // only respond when top
48 | debugMessage("| onMessage: getActiveDevice | sendResponse:", activeDevice);
49 | sendResponse(activeDevice);
50 | }
51 | break;
52 | case "getMicPolicy":
53 | // The extension popup is asking us, whether we will be able to set
54 | // non-default audio devices. Note that we cannot overide a "denied"
55 | // policy of a site (response header) by letting the service worker
56 | // change contentSettings["microphone"] to "allow", e. g.
57 | // https://stackoverflow.com sends in its header
58 | // Feature-Policy: microphone 'none'; speaker 'none'
59 | // which results in a "denied" policy for "microphone" access
60 | // (and the invalid value "speaker 'none'" to be ignored).
61 | if (window === top) { // only respond when top
62 | navigator.permissions.query({name: "microphone"}).then(function(result) {
63 | sendResponse(result.state);
64 | });
65 | // We need to return true from onMessage() to keep the channel open,
66 | // since our sendReponse() is called asynchronously here.
67 | return true;
68 | }
69 | }
70 | }
71 |
72 | async function wakeupWorker() {
73 | try {
74 | await chrome.runtime.sendMessage({
75 | action: "wakeup",
76 | value: "now"
77 | });
78 | } catch {
79 | debugMessage("| wakeupWorker: Worker is hopefully awake now.");
80 | }
81 | return true;
82 | }
83 |
84 | // Send the new/selected sinkId to MAIN.
85 | async function injectSinkId() {
86 | var micPolicy = await navigator.permissions.query({ name: "microphone" });
87 | debugMessage("| injectSink:", activeSinkId, "| micPolicy.state:", micPolicy.state);
88 | if (micPolicy.state === "denied") {
89 | // Do not try to get microphone access and/or change sinkIds.
90 | return;
91 | }
92 | // If we're setting the device to something non-default get Mic access.
93 | if (activeSinkId && (activeSinkId !== "default")) {
94 | // NOTE that the worker uses top's domain (sender.tab.url) to grant
95 | // permission to, not the child's (iframe's).
96 | await chrome.runtime.sendMessage({
97 | action: "setMicAccess",
98 | value: "allow"
99 | });
100 | }
101 | // If we have an activeSinkId.
102 | if (activeSinkId) {
103 | // Send the message to our worker to inject the sinkId and apply.
104 | await chrome.runtime.sendMessage({
105 | action: "injectSink",
106 | value: activeSinkId
107 | });
108 | }
109 | }
110 |
111 | // Set the specified device as the audio sink for all elements.
112 | async function setAudioDevice(deviceName) {
113 | var mediaDeviceInfo;
114 | var sinkId = "default";
115 | var micPolicy = await navigator.permissions.query({ name: "microphone" });
116 | debugMessage("| setAudioDevice:", deviceName, "| micPolicy.state:", micPolicy.state);
117 | if (micPolicy.state === "denied") {
118 | // Do not try to get microphone access and/or change sinkIds.
119 | return;
120 | }
121 | // Send a dumnmy message to wake up the service worker
122 | // This is a hack/workaround for a chrome bug on linux
123 | await wakeupWorker();
124 | // If the target device is the system default skip straight to applying.
125 | if (deviceName !== "default") {
126 | // If we're setting it to anything other than the system default
127 | // make sure we have microphone access before we proceed.
128 | // NOTE that the worker uses top's domain (sender.tab.url) to grant
129 | // permission to, not the child's (iframe's).
130 | await chrome.runtime.sendMessage({
131 | action: "setMicAccess",
132 | value: "allow"
133 | });
134 | // Get the current list of audio devices.
135 | mediaDeviceInfo = await navigator.mediaDevices.enumerateDevices();
136 | mediaDeviceInfo.every(function (device) {
137 | // Skip any audio input devices or devices without deviceIds.
138 | if ((device.kind === "audiooutput") && device.deviceId &&
139 | // If the device label or device id matches our device name
140 | // then set our sinkId to the deviceId.
141 | ((device.label === deviceName) || (device.deviceId === deviceName))) {
142 | sinkId = device.deviceId;
143 | return false;
144 | }
145 | return true;
146 | });
147 | }
148 | // Set our selected sinkId as the active.
149 | activeSinkId = sinkId;
150 | // Set the active device name to the sinkId for default devices.
151 | // Set it to the device label/name otherwise.
152 | if ((sinkId === "default") || (sinkId === "communications")) {
153 | activeDevice = sinkId;
154 | } else {
155 | activeDevice = deviceName;
156 | }
157 | // Update all elements on the page with the new sinkId.
158 | await injectSinkId();
159 | }
160 |
161 | async function init() {
162 | // Inject enableDebug setting into MAIN
163 | const result = await chrome.storage.local.get(["enableDebug"]);
164 | if (result && result.enableDebug) {
165 | await injectDebug(true);
166 | } else {
167 | await injectDebug(false);
168 | }
169 | if (window === top) {
170 | // If we are top, check for a stored/starred activeDevice.
171 | const domainString = storagePrefix + window.location.hostname;
172 | const storage = await chrome.storage.local.get([domainString]);
173 | if (storage[domainString]) {
174 | activeDevice = storage[domainString];
175 | }
176 | } else {
177 | // If we are sub, request the activeDevice from top via worker.
178 | const sleep = function(milliseconds) {
179 | return new Promise((resolve) => setTimeout(resolve, milliseconds));
180 | }
181 | // Max 3 attempts with 200ms wait before trying
182 | for (let tries = 3; tries > 0; tries--) {
183 | await sleep(200);
184 | activeDevice = await chrome.runtime.sendMessage({action: "getActiveDeviceBG"});
185 | if (activeDevice) { break; }
186 | }
187 | if (!activeDevice) {
188 | debugMessage("| init: top content script not responding. Giving up.");
189 | return;
190 | }
191 | }
192 | // Start listening for messages.
193 | debugMessage("| init: addListener(onMessage)");
194 | chrome.runtime.onMessage.addListener(onMessage);
195 | await setAudioDevice(activeDevice);
196 | }
197 |
198 | init();
199 |
--------------------------------------------------------------------------------
/extension/popup.css:
--------------------------------------------------------------------------------
1 | :root {
2 | /* Fonts we have used originally
3 | --sans-font: Noto, "Segoe UI", Arial, Helvetica, sans-serif;
4 | --mono-font: Consolas, "Noto Sans Mono", Menlo, Monaco, monospace;
5 | */
6 |
7 | /* GitHub websafe fonts */
8 | --sans-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
9 | --mono-font: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
10 |
11 | --base-font-size: 1rem;
12 | --medium-font-size: .9rem;
13 | --mono-font-size: .8125rem;
14 | --small-font-size: .8rem;
15 | --tiny-font-size: .625rem;
16 | --line-height: 1.5;
17 | --min-content-width: 38rem;
18 |
19 | --logo-red: #D04949;
20 | --logo-green: #00C25E;
21 | --logo-blue: #3D67FF;
22 | --logo-yellow: #F5B62E;
23 | --logo-white: #E0E0E0;
24 | --logo-gray: #727C92;
25 | --logo-black: #121322;
26 |
27 | --bg: #F0F0F0;
28 | --accent-bg: #E8E8E8;
29 | --text: #212121;
30 | --text-light: #585858;
31 | --border: #D8DAE1;
32 | --accent: var(--logo-blue);
33 | --accent-light: var(--logo-green);
34 | --code: var(--text);
35 | --preformatted: var(--text);
36 | --disabled: #808080;
37 |
38 | --animation-color: var(--logo-green);
39 | --animation-play-state: running;
40 | }
41 |
42 | @media screen and (prefers-color-scheme: dark) {
43 | :root {
44 | --bg: #212121;
45 | --accent-bg: #2B2B2B;
46 | --text: #DCDCDC;
47 | --text-light: #ABABAB;
48 | --border: #666;
49 | --accent: var(--logo-blue);
50 | --accent-light: var(--logo-green);
51 | --code: var(--text);
52 | --preformatted: var(--text);
53 | --disabled: #808080;
54 | }
55 | }
56 |
57 | @media (prefers-reduced-motion) {
58 | :root {
59 | --animation-play-state: paused;
60 | }
61 | }
62 |
63 | html {
64 | color-scheme: light dark;
65 | }
66 |
67 | body {
68 | color: var(--text);
69 | background: var(--bg);
70 | font-family: var(--sans-font);
71 | font-size: var(--base-font-size);
72 | line-height: var(--line-height);
73 | padding: 0;
74 | width: auto;
75 | margin: auto;
76 | }
77 |
78 | header { /* a>h1>svg | div>svg | div>text | div>space | img */
79 | background: var(--accent-bg);
80 | border-bottom: 1px solid var(--border);
81 | margin: 0;
82 | padding: .5rem;
83 | display: flex;
84 | justify-content: space-between;
85 | flex-direction: row;
86 | align-items: center;
87 | min-width: var(--min-content-width);
88 | }
89 | header img { width: 2rem; height: 2rem; }
90 |
91 | a, a:visited {
92 | color: inherit;
93 | text-decoration: none;
94 | }
95 |
96 | a:hover {
97 | color: var(--accent-light);
98 | text-decoration: underline var(--accent) .2rem;
99 | }
100 |
101 | a:focus, input:focus {
102 | outline: none;
103 | }
104 |
105 | svg.lucide {
106 | stroke: currentColor;
107 | width: 1rem;
108 | height: 1rem;
109 | }
110 |
111 | header a h1 svg.lucide {
112 | width: 1.25rem;
113 | height: 1.25rem;
114 | stroke-width: 3;
115 | }
116 |
117 | @keyframes blend-in-and-out {
118 | 0% { opacity: 1.0; color: var(--text-light); }
119 | 20% { opacity: 0.2; color: var(--animation-color); }
120 | 40% { opacity: 1.0; color: var(--animation-color); }
121 | 60% { opacity: 1.0; color: var(--animation-color); }
122 | 80% { opacity: 0.2; color: var(--animation-color); }
123 | 100% { opacity: 1.0; color: var(--text-light); }
124 | }
125 |
126 | header div {
127 | display: inline-block;
128 | text-align: left;
129 | font-size: var(--small-font-size);
130 | color: var(--text-light);
131 | animation-name: blend-in-and-out;
132 | animation-delay: 1s;
133 | animation-duration: 3s;
134 | animation-iteration-count: 1;
135 | animation-play-state: paused;
136 | opacity: 1.0;
137 | min-width: 4rem;
138 | }
139 |
140 | div.animation-enabled {
141 | animation-play-state: var(--animation-play-state);
142 | }
143 |
144 | header div:nth-child(2) { /* div for svg.lucide "chevrons-left" */
145 | opacity: 1.0;
146 | min-width: 2rem;
147 | }
148 |
149 | header div:nth-child(2) svg.lucide { /* svg.lucide "chevrons-left" */
150 | width: 2rem;
151 | height: 2rem;
152 | stroke-width: 2;
153 | display: block;
154 | margin: auto;
155 | }
156 |
157 | header div:nth-child(3) { /* message */
158 | width: 17rem;
159 | }
160 |
161 | h1 { /* only used in header */
162 | font-size: calc(var(--base-font-size) * 1.25);
163 | font-weight: bold;
164 | margin: 0;
165 | }
166 |
167 | h2 { /* only used in main */
168 | font-size: calc(var(--base-font-size) * 1.0);
169 | font-weight: bold;
170 | margin: 0;
171 | }
172 |
173 | main {
174 | margin: 0;
175 | padding: .5rem;
176 | min-width: var(--min-content-width);
177 | }
178 |
179 | table {
180 | width: 100%;
181 | margin-top: .5rem;
182 | margin-bottom: .5rem;
183 | border-collapse: collapse;
184 | background: var(--accent-bg);
185 | }
186 |
187 | td {
188 | text-align: left;
189 | vertical-align: middle;
190 | padding: .5rem;
191 | border-top: 1px solid var(--bg);
192 | border-bottom: 1px solid var(--bg);
193 | }
194 |
195 | tr:first-child td {
196 | border-top: 1px solid var(--border);
197 | border-bottom: 1px solid var(--border);
198 | }
199 |
200 | tr:nth-child(2) td {
201 | border-top: 1px solid var(--border);
202 | }
203 |
204 | tr:first-child td:first-child img { /* table first row, favicon */
205 | padding: 0;
206 | margin: auto;
207 | width: 1.25rem;
208 | height: 1.25rem;
209 | text-align: center;
210 | vertical-align: baseline;
211 | }
212 |
213 | tr:first-child td:nth-child(2) { /* table first row, site */
214 | font-family: var(--mono-font);
215 | font-size: var(--mono-font-size);
216 | font-weight: bold;
217 | overflow-wrap: anywhere;
218 | }
219 |
220 | /* from second row onwards ... */
221 | tr ~ tr td:first-child { /* */
222 | width: 0;
223 | text-align: center;
224 | }
225 |
226 | tr ~ tr td:nth-child(2) { /* */
227 | min-width: 90%;
228 | }
229 |
230 | tr ~ tr td:nth-child(3) { /* &★ */
231 | width: 0;
232 | text-align: right;
233 | color: var(--logo-yellow);
234 | }
235 |
236 | tr.disabled > td {
237 | color: var(--disabled);
238 | font-style: italic;
239 | }
240 |
241 | tr.disabled > td img {
242 | opacity: 0.75;
243 | }
244 |
245 | td.micPolicy-prompt {
246 | color: var(--logo-blue);
247 | }
248 |
249 | td.micPolicy-granted {
250 | color: var(--logo-green);
251 | }
252 |
253 | tr.disabled td.micPolicy-denied {
254 | color: var(--logo-red);
255 | }
256 |
257 | td label {
258 | font-family: var(--mono-font);
259 | font-size: var(--mono-font-size);
260 | overflow-wrap: anywhere;
261 | }
262 |
263 | td label span {
264 | color: var(--disabled);
265 | font-style: italic;
266 | }
267 |
268 | main nav {
269 | display: flex;
270 | justify-content: space-between;
271 | flex-direction: row;
272 | align-items: center;
273 | }
274 |
275 | main nav.options div {
276 | display: inline-block;
277 | min-width: 2rem;
278 | }
279 |
280 | main nav.options div input {
281 | vertical-align: bottom;
282 | }
283 |
284 | main nav.options div label {
285 | font-family: var(--sans-font);
286 | font-size: var(--small-font-size);
287 | vertical-align: bottom;
288 | }
289 |
290 | main nav.buttons {
291 | margin-top: 0.5rem;
292 | }
293 |
294 | button {
295 | vertical-align: middle;
296 | text-align: center;
297 | font-size: var(--medium-font-size);
298 | border: 1px solid var(--border);
299 | outline: none;
300 | background-color: var(--accent-bg);
301 | color: var(--text);
302 | width: 12rem;
303 | height: 2.25rem;
304 | }
305 |
306 | button:hover {
307 | font-weight: bold;
308 | background-color: var(--logo-blue);
309 | color: var(--logo-white);
310 | }
311 |
312 | button[disabled], button[disabled]:hover {
313 | font-weight: normal;
314 | font-style: italic;
315 | background-color: var(--bg);
316 | color: var(--border);
317 | }
318 |
319 | button#cancel:hover {
320 | background-color: var(--logo-red);
321 | color: var(--logo-white);
322 | }
323 |
324 | footer {
325 | background: var(--accent-bg);
326 | border-top: 1px solid var(--border);
327 | margin: 0;
328 | padding: .5rem;
329 | display: flex;
330 | justify-content: space-between;
331 | flex-direction: row;
332 | min-width: var(--min-content-width);
333 | font-weight: bold;
334 | font-size: var(--small-font-size);
335 | color: var(--text-light);
336 | }
337 |
338 | footer a {
339 | /* make both links same width to center the error message */
340 | width: 9rem;
341 | }
342 |
343 | footer a ~ a {
344 | text-align: right;
345 | }
346 |
347 | footer span { /* error/status message */
348 | color: var(--logo-red);
349 | }
350 |
--------------------------------------------------------------------------------
/resources/WebRTC/_/css/fonts.css:
--------------------------------------------------------------------------------
1 | /* cyrillic-ext */
2 | @font-face {
3 | font-family: 'Roboto';
4 | font-style: normal;
5 | font-weight: 300;
6 | src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/0eC6fl06luXEYWpBSJvXCBJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
7 | unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
8 | }
9 | /* cyrillic */
10 | @font-face {
11 | font-family: 'Roboto';
12 | font-style: normal;
13 | font-weight: 300;
14 | src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/Fl4y0QdOxyyTHEGMXX8kcRJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
15 | unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
16 | }
17 | /* greek-ext */
18 | @font-face {
19 | font-family: 'Roboto';
20 | font-style: normal;
21 | font-weight: 300;
22 | src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/-L14Jk06m6pUHB-5mXQQnRJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
23 | unicode-range: U+1F00-1FFF;
24 | }
25 | /* greek */
26 | @font-face {
27 | font-family: 'Roboto';
28 | font-style: normal;
29 | font-weight: 300;
30 | src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/I3S1wsgSg9YCurV6PUkTORJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
31 | unicode-range: U+0370-03FF;
32 | }
33 | /* vietnamese */
34 | @font-face {
35 | font-family: 'Roboto';
36 | font-style: normal;
37 | font-weight: 300;
38 | src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/NYDWBdD4gIq26G5XYbHsFBJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
39 | unicode-range: U+0102-0103, U+1EA0-1EF9, U+20AB;
40 | }
41 | /* latin-ext */
42 | @font-face {
43 | font-family: 'Roboto';
44 | font-style: normal;
45 | font-weight: 300;
46 | src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/Pru33qjShpZSmG3z6VYwnRJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
47 | unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
48 | }
49 | /* latin */
50 | @font-face {
51 | font-family: 'Roboto';
52 | font-style: normal;
53 | font-weight: 300;
54 | src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/Hgo13k-tfSpn0qi1SFdUfVtXRa8TVwTICgirnJhmVJw.woff2) format('woff2');
55 | unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
56 | }
57 | /* cyrillic-ext */
58 | @font-face {
59 | font-family: 'Roboto';
60 | font-style: normal;
61 | font-weight: 400;
62 | src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/ek4gzZ-GeXAPcSbHtCeQI_esZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
63 | unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
64 | }
65 | /* cyrillic */
66 | @font-face {
67 | font-family: 'Roboto';
68 | font-style: normal;
69 | font-weight: 400;
70 | src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/mErvLBYg_cXG3rLvUsKT_fesZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
71 | unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
72 | }
73 | /* greek-ext */
74 | @font-face {
75 | font-family: 'Roboto';
76 | font-style: normal;
77 | font-weight: 400;
78 | src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/-2n2p-_Y08sg57CNWQfKNvesZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
79 | unicode-range: U+1F00-1FFF;
80 | }
81 | /* greek */
82 | @font-face {
83 | font-family: 'Roboto';
84 | font-style: normal;
85 | font-weight: 400;
86 | src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/u0TOpm082MNkS5K0Q4rhqvesZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
87 | unicode-range: U+0370-03FF;
88 | }
89 | /* vietnamese */
90 | @font-face {
91 | font-family: 'Roboto';
92 | font-style: normal;
93 | font-weight: 400;
94 | src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/NdF9MtnOpLzo-noMoG0miPesZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
95 | unicode-range: U+0102-0103, U+1EA0-1EF9, U+20AB;
96 | }
97 | /* latin-ext */
98 | @font-face {
99 | font-family: 'Roboto';
100 | font-style: normal;
101 | font-weight: 400;
102 | src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/Fcx7Wwv8OzT71A3E1XOAjvesZW2xOQ-xsNqO47m55DA.woff2) format('woff2');
103 | unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
104 | }
105 | /* latin */
106 | @font-face {
107 | font-family: 'Roboto';
108 | font-style: normal;
109 | font-weight: 400;
110 | src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v15/CWB0XYA8bzo0kSThX0UTuA.woff2) format('woff2');
111 | unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
112 | }
113 | /* cyrillic-ext */
114 | @font-face {
115 | font-family: 'Roboto';
116 | font-style: normal;
117 | font-weight: 500;
118 | src: local('Roboto Medium'), local('Roboto-Medium'), url(https://fonts.gstatic.com/s/roboto/v15/ZLqKeelYbATG60EpZBSDyxJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
119 | unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
120 | }
121 | /* cyrillic */
122 | @font-face {
123 | font-family: 'Roboto';
124 | font-style: normal;
125 | font-weight: 500;
126 | src: local('Roboto Medium'), local('Roboto-Medium'), url(https://fonts.gstatic.com/s/roboto/v15/oHi30kwQWvpCWqAhzHcCSBJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
127 | unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
128 | }
129 | /* greek-ext */
130 | @font-face {
131 | font-family: 'Roboto';
132 | font-style: normal;
133 | font-weight: 500;
134 | src: local('Roboto Medium'), local('Roboto-Medium'), url(https://fonts.gstatic.com/s/roboto/v15/rGvHdJnr2l75qb0YND9NyBJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
135 | unicode-range: U+1F00-1FFF;
136 | }
137 | /* greek */
138 | @font-face {
139 | font-family: 'Roboto';
140 | font-style: normal;
141 | font-weight: 500;
142 | src: local('Roboto Medium'), local('Roboto-Medium'), url(https://fonts.gstatic.com/s/roboto/v15/mx9Uck6uB63VIKFYnEMXrRJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
143 | unicode-range: U+0370-03FF;
144 | }
145 | /* vietnamese */
146 | @font-face {
147 | font-family: 'Roboto';
148 | font-style: normal;
149 | font-weight: 500;
150 | src: local('Roboto Medium'), local('Roboto-Medium'), url(https://fonts.gstatic.com/s/roboto/v15/mbmhprMH69Zi6eEPBYVFhRJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
151 | unicode-range: U+0102-0103, U+1EA0-1EF9, U+20AB;
152 | }
153 | /* latin-ext */
154 | @font-face {
155 | font-family: 'Roboto';
156 | font-style: normal;
157 | font-weight: 500;
158 | src: local('Roboto Medium'), local('Roboto-Medium'), url(https://fonts.gstatic.com/s/roboto/v15/oOeFwZNlrTefzLYmlVV1UBJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
159 | unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
160 | }
161 | /* latin */
162 | @font-face {
163 | font-family: 'Roboto';
164 | font-style: normal;
165 | font-weight: 500;
166 | src: local('Roboto Medium'), local('Roboto-Medium'), url(https://fonts.gstatic.com/s/roboto/v15/RxZJdnzeo3R5zSexge8UUVtXRa8TVwTICgirnJhmVJw.woff2) format('woff2');
167 | unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
168 | }
169 | /* cyrillic-ext */
170 | @font-face {
171 | font-family: 'Roboto';
172 | font-style: normal;
173 | font-weight: 700;
174 | src: local('Roboto Bold'), local('Roboto-Bold'), url(https://fonts.gstatic.com/s/roboto/v15/77FXFjRbGzN4aCrSFhlh3hJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
175 | unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
176 | }
177 | /* cyrillic */
178 | @font-face {
179 | font-family: 'Roboto';
180 | font-style: normal;
181 | font-weight: 700;
182 | src: local('Roboto Bold'), local('Roboto-Bold'), url(https://fonts.gstatic.com/s/roboto/v15/isZ-wbCXNKAbnjo6_TwHThJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
183 | unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
184 | }
185 | /* greek-ext */
186 | @font-face {
187 | font-family: 'Roboto';
188 | font-style: normal;
189 | font-weight: 700;
190 | src: local('Roboto Bold'), local('Roboto-Bold'), url(https://fonts.gstatic.com/s/roboto/v15/UX6i4JxQDm3fVTc1CPuwqhJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
191 | unicode-range: U+1F00-1FFF;
192 | }
193 | /* greek */
194 | @font-face {
195 | font-family: 'Roboto';
196 | font-style: normal;
197 | font-weight: 700;
198 | src: local('Roboto Bold'), local('Roboto-Bold'), url(https://fonts.gstatic.com/s/roboto/v15/jSN2CGVDbcVyCnfJfjSdfBJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
199 | unicode-range: U+0370-03FF;
200 | }
201 | /* vietnamese */
202 | @font-face {
203 | font-family: 'Roboto';
204 | font-style: normal;
205 | font-weight: 700;
206 | src: local('Roboto Bold'), local('Roboto-Bold'), url(https://fonts.gstatic.com/s/roboto/v15/PwZc-YbIL414wB9rB1IAPRJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
207 | unicode-range: U+0102-0103, U+1EA0-1EF9, U+20AB;
208 | }
209 | /* latin-ext */
210 | @font-face {
211 | font-family: 'Roboto';
212 | font-style: normal;
213 | font-weight: 700;
214 | src: local('Roboto Bold'), local('Roboto-Bold'), url(https://fonts.gstatic.com/s/roboto/v15/97uahxiqZRoncBaCEI3aWxJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
215 | unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
216 | }
217 | /* latin */
218 | @font-face {
219 | font-family: 'Roboto';
220 | font-style: normal;
221 | font-weight: 700;
222 | src: local('Roboto Bold'), local('Roboto-Bold'), url(https://fonts.gstatic.com/s/roboto/v15/d-6IYplOFocCacKzxwXSOFtXRa8TVwTICgirnJhmVJw.woff2) format('woff2');
223 | unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
224 | }
225 |
--------------------------------------------------------------------------------
/extension/main.js:
--------------------------------------------------------------------------------
1 | // Main script handles:
2 | // 1) Hooking AudioContext, Element, and HTMLMediaElement prototypes.
3 | // 2) Monitoring the creation of new elements with a MutationObserver.
4 | // 3) Injecting a listener and applying the SinkId to VIDEO and AUDIO elements.
5 | // Main script runs in WORLD:MAIN.
6 | //
7 | // Unique prefix for our global variable and function names: APV3_UN1QU3_
8 | // More possible name collisions we currently do not address, e. g.
9 | // - Element.sinkListener (property name)
10 | // - document.queryShadowSelectorAll (property name)
11 | // - changeSinkId (message/event name)
12 |
13 | // Observer function that will be called for any new nodes or shadowRoots.
14 | const APV3_UN1QU3_observer = new MutationObserver(function (mutations) {
15 | // Check each mutation to see if nodes have been added.
16 | mutations.forEach(function (mutation) {
17 | // If nodes have been added then recursively update sinkId on all.
18 | mutation.addedNodes.forEach(function (node) {
19 | APV3_UN1QU3_recursiveSetSinkId(node);
20 | });
21 | });
22 | });
23 |
24 | // Write to console.log, if debugging is enabled.
25 | function APV3_UN1QU3_debugMessage(...args) {
26 | if (window.APV3_UN1QU3_enableDebug) {
27 | console.log('APV3-main.js (' +
28 | ((window === top) ? 'top-origin: ' : 'sub-origin: ') +
29 | window.location.origin + ')', ...args);
30 | }
31 | }
32 |
33 | async function APV3_UN1QU3_maybeSetSinkId(targetElement, trigger, sinkId) {
34 | if (sinkId === "default") {
35 | sinkId = "";
36 | }
37 | if (sinkId === targetElement.sinkId) {
38 | return true;
39 | }
40 | if ((targetElement instanceof HTMLMediaElement) && (targetElement.sourceOfAudioContext)) {
41 | // Skip setsinkId() on HTMLMediaElement(s)s that were used to
42 | // create MediaElementAudioSourceNode(s) of an AudioContext.
43 | APV3_UN1QU3_debugMessage("| " + trigger + "(skip):", targetElement.constructor.name, "| targetElement:", targetElement,
44 | "| sourceOfAudioContext:", targetElement.sourceOfAudioContext, "| foundViaMethod:", targetElement.foundViaMethod);
45 | return false;
46 | }
47 | try {
48 | APV3_UN1QU3_debugMessage("| " + trigger + "(try):", targetElement.constructor.name, "| targetElement:", targetElement,
49 | "| sourceOfAudioContext:", targetElement.sourceOfAudioContext, "| foundViaMethod:", targetElement.foundViaMethod,
50 | "| oldSinkId:", targetElement.sinkId, "| sinkId:", sinkId);
51 | await targetElement.setSinkId(sinkId);
52 | return true;
53 | } catch(error) {
54 | APV3_UN1QU3_debugMessage("| " + trigger + "(catch):", targetElement.constructor.name, "| targetElement:", targetElement,
55 | "| sourceOfAudioContext:", targetElement.sourceOfAudioContext, "| foundViaMethod:", targetElement.foundViaMethod,
56 | "| oldSinkId:", targetElement.sinkId, "| sinkId:", sinkId, "| error:", error);
57 | return false;
58 | }
59 | }
60 |
61 | // The function we call to initially add the eventListener and set the sinkId.
62 | // Can be called on any HTMLMediaElement or descendants.
63 | async function APV3_UN1QU3_addListenerAndSetSinkId(targetElement, method) {
64 | targetElement.foundViaMethod = method;
65 | if (typeof(targetElement.sinkListener) !== "function") {
66 | targetElement.sinkListener = function (e) {
67 | APV3_UN1QU3_maybeSetSinkId(targetElement, "changeSinkId", e.detail);
68 | }
69 | // Add event listener to top for ease of event management.
70 | window.addEventListener("changeSinkId", targetElement.sinkListener, true);
71 | // Only try to set the sinkId, if we have an activeSinkId already.
72 | // ... and only once when (only) found via addEventListener_*_hook
73 | if ((typeof window.APV3_UN1QU3_activeSinkId !== "undefined") && method.startsWith("addEventListener_")) {
74 | await APV3_UN1QU3_maybeSetSinkId(targetElement, "setSinkId", window.APV3_UN1QU3_activeSinkId);
75 | }
76 | }
77 | // Only try to set the sinkId, if we have an activeSinkId already.
78 | // ... and only once when (only) found via addEventListener_*_hook
79 | if ((typeof window.APV3_UN1QU3_activeSinkId !== "undefined") && !method.startsWith("addEventListener_")) {
80 | await APV3_UN1QU3_maybeSetSinkId(targetElement, "setSinkId", window.APV3_UN1QU3_activeSinkId);
81 | }
82 | }
83 |
84 | // Function to recursively set the sinkId on any audio/video elements.
85 | // It will recursively apply to all children and shadowRoots.
86 | async function APV3_UN1QU3_recursiveSetSinkId(node) {
87 | var queue = [];
88 | // If there are children queue each one up to pass back to this function.
89 | if (node.hasChildNodes()) {
90 | node.childNodes.forEach(function (child) {
91 | queue.push(APV3_UN1QU3_recursiveSetSinkId(child));
92 | });
93 | }
94 | // If there are shadowRoots make sure they're being observed.
95 | // Then queue each child to send back to this function.
96 | if (node.shadowRoot) {
97 | APV3_UN1QU3_observer.observe(node.shadowRoot, {childList: true,subtree: true});
98 | node.shadowRoot.childNodes.forEach(function (child) {
99 | queue.push(APV3_UN1QU3_recursiveSetSinkId(child));
100 | });
101 | }
102 | // If the current node is an audio/video node then set the sinkId.
103 | if ((node.nodeName === "AUDIO") || (node.nodeName === "VIDEO")) {
104 | await APV3_UN1QU3_addListenerAndSetSinkId(node, "observer_recursiveSetSinkId");
105 | }
106 | // Process all children.
107 | await Promise.all(queue);
108 | return true;
109 | }
110 |
111 | // Hook some HTMLMediaElement.prototype methods to catch
112 | // elements that are created outside of the DOM tree.
113 | function APV3_UN1QU3_hookHTMLMediaElement_various() {
114 | // Alias HTMLMediaElement.prototype to allow for shorter line length.
115 | const ME = HTMLMediaElement.prototype;
116 | // Don't double-hook if we already did in this context.
117 | if (typeof(ME.play_noHook) !== "function") {
118 | // Save the original functions for callback.
119 | ME.play_noHook = ME.play;
120 | ME.load_noHook = ME.load;
121 | ME.addEventListener_noHook = ME.addEventListener;
122 | }
123 | // Set our hooks
124 | // Each hooked function simply calls addListenerAndSetSinkId on the object
125 | // before calling and returning the value from the original function.
126 | // Make hooks async when the hooked function returns a promise
127 | // and we don't want to handle/catch possible errors, e. g. play() being
128 | // denied due to autoplay restrictions.
129 | ME.play = async function(...args) {
130 | APV3_UN1QU3_addListenerAndSetSinkId(this, "play_hook");
131 | return this.play_noHook.apply(this, args);
132 | };
133 | ME.load = function(...args) {
134 | APV3_UN1QU3_addListenerAndSetSinkId(this, "load_hook");
135 | return this.load_noHook.apply(this, args);
136 | };
137 | ME.addEventListener = function(...args) {
138 | APV3_UN1QU3_addListenerAndSetSinkId(this, "addEventListener_" + args[0] + "_hook");
139 | return this.addEventListener_noHook.apply(this, args);
140 | };
141 | }
142 |
143 | // Hook all AudioContext.prototype create functions to catch any AudioContexts.
144 | function APV3_UN1QU3_hookAudioContext_create() {
145 | // Alias AudioContext.prototype to allow for shorter line length.
146 | const AC = AudioContext.prototype;
147 | // Don't double-hook if we already did in this context.
148 | if (typeof(AC.createMediaElementSource_noHook) !== "function") {
149 | // Save the original functions for callback.
150 | AC.createMediaElementSource_noHook = AC.createMediaElementSource;
151 | AC.createMediaStreamSource_noHook = AC.createMediaStreamSource;
152 | AC.createMediaStreamDestination_noHook = AC.createMediaStreamDestination;
153 | AC.createMediaStreamTrackSource_noHook = AC.createMediaStreamTrackSource;
154 | }
155 | // Set our hooks
156 | // Each hooked function simply calls addListenerAndSetSinkId on the object
157 | // before calling and returning the value from the original function.
158 | AC.createMediaElementSource = function(...args) {
159 | APV3_UN1QU3_addListenerAndSetSinkId(this, "createMediaElementSource_hook");
160 | // Mark the HTMLMediaElement (args[0]) used to create the MediaElementAudioSourceNode
161 | // as being used by an AudioContext to prevent calling setSinkId() on it.
162 | args[0].sourceOfAudioContext = true;
163 | return this.createMediaElementSource_noHook.apply(this, args);
164 | };
165 | AC.createMediaStreamSource = function(...args) {
166 | APV3_UN1QU3_addListenerAndSetSinkId(this, "createMediaStreamSource_hook");
167 | return this.createMediaStreamSource_noHook.apply(this, args);
168 | };
169 | AC.createMediaStreamDestination = function(...args) {
170 | APV3_UN1QU3_addListenerAndSetSinkId(this, "createMediaStreamDestination_hook");
171 | return this.createMediaStreamDestination_noHook.apply(this, args);
172 | };
173 | AC.createMediaStreamTrackSource = function(...args) {
174 | APV3_UN1QU3_addListenerAndSetSinkId(this, "createMediaStreamTrackSource_hook");
175 | return this.createMediaStreamTrackSource_noHook.apply(this, args);
176 | };
177 | }
178 |
179 | // Hook Element.prototype.attachShadow so we see any shadowRoots created.
180 | function APV3_UN1QU3_hookElement_attachShadow() {
181 | // Don't double-hook if we already did in this context.
182 | if (typeof(Element.prototype.attachShadow_noHook) !== "function") {
183 | // Save the original function for callback.
184 | Element.prototype.attachShadow_noHook = Element.prototype.attachShadow;
185 | }
186 | // Set our hook.
187 | Element.prototype.attachShadow = function(options) {
188 | // Create the shadowRoot with the original function.
189 | var s = this.attachShadow_noHook.apply(this, arguments);
190 | // Attach our observer to watch for any changes.
191 | APV3_UN1QU3_observer.observe(s, {childList: true, subtree: true});
192 | // Recursively set sinkIDs on any existing children.
193 | APV3_UN1QU3_recursiveSetSinkId(s);
194 | // Return the requested shadowRoot.
195 | return s;
196 | };
197 | }
198 |
199 | // Essentially document.querySelectorAll for shadowRoots.
200 | // Allows us to find any shadowRoots or children that were previously created.
201 | document.queryShadowSelectorAll = function(selectors, e = document) {
202 | // Recursive function to locate all shadowRoots for the provided element.
203 | var getShadowRoots = function (el) {
204 | var shadowRoots = [el, ...el.querySelectorAll("*")];
205 | return shadowRoots.filter((ce) => Boolean(ce.shadowRoot))
206 | .flatMap((ce) => [ce.shadowRoot, ...getShadowRoots(ce.shadowRoot)]);
207 | };
208 | var shadowMap = getShadowRoots(e);
209 | var results = [];
210 | // Get every element from every shadowRoot.
211 | shadowMap.forEach(function (shadow) {
212 | var s = shadow.querySelectorAll(":host *");
213 | if (s) {s.forEach(
214 | function (el) {
215 | results.push(el);
216 | }
217 | );}
218 | });
219 | // Filter results to our selectors.
220 | return results.filter(
221 | function (r) {
222 | return r.matches(selectors);
223 | }
224 | );
225 | };
226 |
227 | // Set the sinkId on every existing audio/video element.
228 | async function APV3_UN1QU3_processAllMediaElements() {
229 | var queue = [];
230 | // Prepare to set sinkId on all audio/video nodes not in shadowRoots.
231 | document.querySelectorAll("audio,video").forEach(function(node) {
232 | queue.push(APV3_UN1QU3_addListenerAndSetSinkId(node, "processAllMediaElements_normal"));
233 | });
234 | // Prepare to set sinkId on all audio/video nodes in shadowRoots.
235 | document.queryShadowSelectorAll("audio,video").forEach(function (node) {
236 | queue.push(APV3_UN1QU3_addListenerAndSetSinkId(node, "processAllMediaElements_shadow"));
237 | });
238 | // Process all located nodes.
239 | ret = await Promise.all(queue);
240 | return ret;
241 | }
242 |
243 | // Load hooks first.
244 | APV3_UN1QU3_hookHTMLMediaElement_various();
245 | APV3_UN1QU3_hookAudioContext_create();
246 | APV3_UN1QU3_hookElement_attachShadow();
247 | // Then start observing the document.
248 | APV3_UN1QU3_observer.observe(document.documentElement, {childList: true,subtree: true});
249 | // Then process any existing media elements to set sinkId and add listener.
250 | APV3_UN1QU3_processAllMediaElements();
251 |
--------------------------------------------------------------------------------
/extension/popup.js:
--------------------------------------------------------------------------------
1 | // Prefix used for our local storage variables.
2 | const storagePrefix = "preferredDevice_";
3 | var tabError = "";
4 | var micPolicy = "unknown";
5 | var activeTab;
6 | var domainString;
7 | // Assume all devices are the system default until proven otherwise.
8 | var domainDevice = "default";
9 | var activeDevice = "default";
10 |
11 | // Write to console.log, if debugging is enabled.
12 | function debugMessage(...args) {
13 | chrome.storage.local.get(["enableDebug"]).then(function(result) {
14 | if (result && result.enableDebug) {
15 | console.log('APV3-popup.js', ...args);
16 | }
17 | });
18 | }
19 |
20 | // OnChange handler for our smart checkbox
21 | function checkboxSmart_OnChange(e) {
22 | if (e.target.checked === true) {
23 | chrome.storage.local.set({"enableSmart": true});
24 | } else {
25 | chrome.storage.local.set({"enableSmart": false});
26 | }
27 | }
28 |
29 | // OnChange handler for our debug checkbox
30 | function checkboxDebug_OnChange(e) {
31 | if (e.target.checked === true) {
32 | chrome.storage.local.set({"enableDebug": true});
33 | } else {
34 | chrome.storage.local.set({"enableDebug": false});
35 | }
36 | chrome.tabs.sendMessage(activeTab.id,
37 | {action: "updateDebug", value: e.target.checked}
38 | ).catch(function() {
39 | // Do nothing.
40 | // There might be no content script running in the target tab.
41 | });
42 | }
43 |
44 | // Sets microphone access using contentSettings API.
45 | async function setMicAccess(pattern, value) {
46 | await chrome.contentSettings.microphone.set({
47 | primaryPattern: pattern,
48 | scope: (
49 | activeTab.incognito
50 | ? "incognito_session_only"
51 | : "regular"
52 | ),
53 | setting: value
54 | });
55 | return true;
56 | }
57 |
58 | // Throw away all microphone permissions managed by us and re-acquire access
59 | // - for domains wich have stored/starred non-default devices
60 | // - for domains from any (currently open) secure (https) tab
61 | // with a non-default activeDevice
62 | // - and for ourselves
63 | // Optionally exclude the (id of the) activeTab for which we are about
64 | // to set a possibly new device which may no longer require access.
65 | async function smartMicAccess(excludedTabId) {
66 | const clearMicAccess = async function() {
67 | await chrome.contentSettings.microphone.clear({
68 | scope: (
69 | activeTab.incognito
70 | ? "incognito_session_only"
71 | : "regular"
72 | )
73 | });
74 | return true;
75 | }
76 | // Remove all microphone permissions managed by us
77 | await clearMicAccess();
78 | // (Re-)Acquire extension's microphone access so we (the popup)
79 | // can access non-default audio devices when we list them.
80 | await setMicAccess("*://" + chrome.runtime.id + "/*", "allow");
81 | // Re-acquire microphone access for domains
82 | // with a stored/starred non-default device.
83 | let items = await chrome.storage.local.get(null);
84 | for (let [key, value] of Object.entries(items)) {
85 | if (key.startsWith(storagePrefix)) {
86 | if (value !== "default") {
87 | let micPattern = "https://" + key.replace(storagePrefix, "") + "/*";
88 | debugMessage("| smartMicAccess(starredDom): allow:", micPattern);
89 | await setMicAccess(micPattern, "allow");
90 | }
91 | }
92 | }
93 | // Re-acquire microphone access for domains
94 | // from secure tabs with a non-default device.
95 | let secureTabs = await chrome.tabs.query({ url: "https://*/*" });
96 | secureTabs.forEach(async function(tab) {
97 | let micPattern = "https://" + tab.url.split("/")[2] + "/*";
98 | if (tab.id === excludedTabId) {
99 | debugMessage("| smartMicAccess(secureTabs): skip excluded:", micPattern);
100 | return;
101 | }
102 | try {
103 | const response = await chrome.tabs.sendMessage(tab.id, {
104 | action: "getActiveDevice"
105 | });
106 | if (response && (response !== "default")) {
107 | debugMessage("| smartMicAccess(secureTabs): allow:", micPattern);
108 | await setMicAccess(micPattern, "allow");
109 | }
110 | } catch {
111 | debugMessage("| smartMicAccess(secureTabs): no response:", micPattern);
112 | }
113 | });
114 | return true;
115 | }
116 |
117 | // Click handler used for all buttons on the popup.
118 | function button_OnClick(e) {
119 | // Just close the window, when cancel has been clicked.
120 | if (e.target.id === "cancel") {
121 | window.close();
122 | return;
123 | }
124 | let selected = document.querySelectorAll("input[type='radio']:checked")[0];
125 | // Remove stored/starred device for domain, if reverting to "default".
126 | if ((e.target.id === "applyStar") && (selected.id === "default")) {
127 | chrome.storage.local.remove([domainString]);
128 | }
129 | let checkboxSmart = document.getElementById("checkbox_smart");
130 | if (!checkboxSmart.checked) {
131 | // If the default device is selected, we don't need microphone access.
132 | // Note that this still marks the microphone permission as managed
133 | // by the extension, i. e. it cannot be changed by the user.
134 | // That's one reason, we added smartMicAccess() ...
135 | if (selected.id === "default") {
136 | let micPattern = activeTab.url.split("/")[0] + "//";
137 | micPattern = micPattern + activeTab.url.split("/")[2] + "/*";
138 | setMicAccess(micPattern, "ask");
139 | }
140 | } else {
141 | // Do not re-acquire microphone permissions for the activeTab,
142 | // since we are doing this implicitely (when needed) below
143 | // through sending a "setActiveDevice" message.
144 | smartMicAccess(activeTab.id);
145 | }
146 | if ((selected.id === "default") || (selected.id === "communications")) {
147 | // If the default audio or comms device was selected we use their ID.
148 | // This avoids mismatches when they change defaults.
149 | activeDevice = selected.id;
150 | } else {
151 | // If a non-default device was selected use the device label.
152 | // Allows us to select the right device between tabs when IDs change.
153 | activeDevice = selected.value;
154 | }
155 | // Tell the active tab to set the newly selected active device.
156 | chrome.tabs.sendMessage(activeTab.id, {
157 | action: "setActiveDevice",
158 | device: activeDevice
159 | }).then(function () {
160 | // If we're here because the user clicked the "applyStar" button,
161 | // we save the selection as "preferred" to the local storage.
162 | if ((e.target.id === "applyStar") && (activeDevice !== "default")) {
163 | chrome.storage.local.set({[domainString]: activeDevice });
164 | }
165 | // Close the popup.
166 | window.close();
167 | });
168 | }
169 |
170 | function addTitleRow(table, url, isDisabled) {
171 | const siteUrl = function(url) {
172 | if (typeof url === 'undefined') {
173 | url = "undefined://undefined";
174 | }
175 | let proto = url.split("/")[0];
176 | let host = url.split("/")[2];
177 | if (proto === "https:") {
178 | return url.split("/")[2];
179 | } else {
180 | return proto + "//" + host;
181 | }
182 | };
183 | const favIconUrl = function(url) {
184 | if (typeof url === 'undefined') {
185 | // A dedicated icon would be better, but this is
186 | // a really rare case, e. g. opening a tab for
187 | // "chrome-extension://" + chrome.runtime.id + "/popup.html"
188 | return "./APV3_Icon_2d_2c_32.png";
189 | }
190 | const query = new URL(chrome.runtime.getURL("/_favicon/"));
191 | query.searchParams.set("pageUrl", url);
192 | query.searchParams.set("size", "32");
193 | return query.toString();
194 | };
195 | const svgMicDeny = `
196 |
207 | `;
208 | const svgMicDefault = `
209 |
217 | `;
218 | let row = table.insertRow(-1);
219 | let cell0 = row.insertCell(0);
220 | let cell1 = row.insertCell(1);
221 | let cell2 = row.insertCell(2);
222 | let site = siteUrl(url);
223 | let siteIcon = favIconUrl(url);
224 | let imageNode = document.createElement("img");
225 | let textNode = document.createTextNode(site + " - mic:" + micPolicy);
226 | imageNode.src = siteIcon;
227 | cell0.appendChild(imageNode);
228 | cell1.appendChild(textNode);
229 | if (isDisabled) {
230 | row.classList.add("disabled");
231 | // micPolicy is either "unknown" or "denied"
232 | cell2.innerHTML = svgMicDeny;
233 | } else {
234 | // micPolicy is either "prompt" or "granted"
235 | cell2.innerHTML = svgMicDefault;
236 | }
237 | cell2.classList.add("micPolicy-" + micPolicy);
238 | }
239 |
240 | function addDeviceRow(table, deviceId, deviceLabel, isActive, isPreferred, isDisabled) {
241 | const reDevicePrefix = /^\s*\S+\s*-\s*/i;
242 | let row = table.insertRow(-1);
243 | let cell0 = row.insertCell(0);
244 | let cell1 = row.insertCell(1);
245 | let cell2 = row.insertCell(2);
246 | let radioElement = document.createElement("input");
247 | let labelElement = document.createElement("label");
248 | radioElement.type = "radio";
249 | radioElement.name = "device";
250 | radioElement.id = deviceId;
251 | // Store the deviceLabel as radioElement.value so we can
252 | // pass it to the activeTab as the (new) activeDevice.
253 | radioElement.value = deviceLabel;
254 | radioElement.checked = isActive;
255 | radioElement.disabled = isDisabled;
256 | if (isDisabled) {
257 | row.classList.add("disabled");
258 | }
259 | // Make standard label for default devices & use provided for rest.
260 | // On Windows and possibly MacOS the device labels for "default" and
261 | // "communications" look like "Default|Communications - ACTUAL_DEVICE_NAME",
262 | // but on Linux it's just "Default" ("communications" does not even exist).
263 | // The following handles both cases.
264 | let deviceSuffix = deviceLabel.replace(reDevicePrefix, ''); /* Strip prefix, if there is one*/
265 | if ((deviceId === "default") && (deviceSuffix !== deviceLabel)) {
266 | labelElement.innerHTML = 'Default - ' + deviceSuffix + '';
267 | } else if ((deviceId === "communications") && (deviceSuffix !== deviceLabel)) {
268 | labelElement.innerHTML = 'Communications - ' + deviceSuffix + '';
269 | } else {
270 | labelElement.innerHTML = deviceLabel;
271 | }
272 | labelElement.htmlFor = deviceId;
273 | cell0.appendChild(radioElement);
274 | cell1.appendChild(labelElement);
275 | if (isPreferred) {
276 | cell2.innerHTML = "★"; // star
277 | } else {
278 | cell2.innerHTML = " "; // blank
279 | }
280 | }
281 |
282 | function buildDeviceTable(mediaDeviceInfo) {
283 | let activeExists = false;
284 | let domainExists = false;
285 | let table = document.getElementById("device_options");
286 | // Remove all existing rows from the device table.
287 | while (table.rows.length > 0) { table.deleteRow(0); }
288 | // Show information about the activeTab's site in the first row,
289 | // i. e. site (host/domain-name), favIcon and micPolicy
290 | addTitleRow(table, activeTab.url, (tabError !== ""));
291 | // Check, if we (still) find the tab's activeDevice and its domain's
292 | // possibly stored "preferred device" (domainDevice) in our current
293 | // list of "audiooutput" devices.
294 | mediaDeviceInfo.forEach(function (device) {
295 | // Filter out input devices.
296 | // We no longer offer the "communications" device, but we still
297 | // handle it as a special case everywhere else, e. g. remember
298 | // the device.deviceId instead of device.label.
299 | if ((device.kind === "audiooutput") && (device.deviceId !== "communications")) {
300 | activeExists = activeExists ||
301 | (device.label === activeDevice) || (device.deviceId === activeDevice);
302 | domainExists = domainExists ||
303 | (device.label === domainDevice) || (device.deviceId === domainDevice);
304 | }
305 | });
306 | // Pick the best match (active > domain > "default") from the list of EXISTING
307 | // "audiooutput" devices, so that it gets pre-selected/checked in the device table.
308 | if (!activeExists) {
309 | if (domainExists) {
310 | activeDevice = domainDevice;
311 | } else {
312 | activeDevice = "default";
313 | }
314 | }
315 | // Generate our device entries.
316 | mediaDeviceInfo.forEach(function (device) {
317 | // Filter out input devices.
318 | // We no longer offer the "communications" device, but we still
319 | // handle it as a special case everywhere else, e. g. remember
320 | // device.deviceId instead of device.label.
321 | if ((device.kind === "audiooutput") && (device.deviceId !== "communications")) {
322 | let isActive = false;
323 | let isPreferred = false;
324 | if (tabError === "") { // tab is valid and has a content script
325 | // Is this the tab's activeDevice?
326 | if ((device.label === activeDevice) || (device.deviceId === activeDevice)) {
327 | isActive = true;
328 | }
329 | // Is this the tab domain`s preferred/starred device?
330 | if ((device.label === domainDevice) || (device.deviceId === domainDevice)) {
331 | isPreferred = true;
332 | }
333 | }
334 | addDeviceRow(table, device.deviceId, device.label, isActive, isPreferred, (tabError !== ""));
335 | }
336 | });
337 | // If the preferred device no longer exists, e. g. was removed or renamed,
338 | // we add a disabled entry to signal this fact to the user.
339 | if (domainDevice && !domainExists) {
340 | addDeviceRow(table, "unknownId", domainDevice, false, true, true);
341 | }
342 | }
343 |
344 | async function init() {
345 | let status = document.getElementById("status_message");
346 | let checkboxDebug = document.getElementById("checkbox_debug");
347 | let checkboxSmart = document.getElementById("checkbox_smart");
348 | let storageResult = await chrome.storage.local.get(["enableDebug", "enableSmart", "lastAnimated"]);
349 | if (storageResult && storageResult.enableDebug) {
350 | checkboxDebug.checked = true;
351 | } else {
352 | checkboxDebug.checked = false;
353 | }
354 | checkboxDebug.onchange = checkboxDebug_OnChange;
355 | if (storageResult && storageResult.enableSmart) {
356 | checkboxSmart.checked = true;
357 | } else {
358 | checkboxSmart.checked = false;
359 | }
360 | checkboxSmart.onchange = checkboxSmart_OnChange;
361 | // Get the current active / calling tab.
362 | [activeTab] = await chrome.tabs.query({
363 | active: true,
364 | currentWindow: true
365 | });
366 | // Check whether the tab has a valid (HTTPS) URL.
367 | if (!activeTab.url || (activeTab.url.toLowerCase().indexOf("https") === -1)) {
368 | tabError = "Invalid URL. Not HTTPS.";
369 | }
370 | if (tabError === "") {
371 | // Generate domain storage name from tab URL.
372 | domainString = storagePrefix + activeTab.url.split("/")[2];
373 | // Retrieve domain settings if they exist.
374 | const storage = await chrome.storage.local.get([domainString]);
375 | if (storage[domainString]) {
376 | domainDevice = storage[domainString];
377 | }
378 | // Get the active device from the current tab.
379 | try {
380 | const response = await chrome.tabs.sendMessage(
381 | activeTab.id, {action: "getActiveDevice"}, {frameId: 0});
382 | if (response) {
383 | activeDevice = response;
384 | }
385 | } catch {
386 | tabError = "Content Script not reponding. Try reload.";
387 | }
388 | }
389 | if (tabError === "") {
390 | // Get the site's Permissions-Policy for microphone access.
391 | try {
392 | const response = await chrome.tabs.sendMessage(
393 | activeTab.id, {action: "getMicPolicy"}, {frameId: 0});
394 | micPolicy = response;
395 | if (response === "denied") {
396 | tabError = "Site denies microphone access.";
397 | }
398 | } catch {
399 | tabError = "Content Script not reponding. Try reload.";
400 | }
401 | }
402 | // Display the current tab status/error.
403 | status.innerHTML = tabError;
404 | // Set our extensions microphone access permissions so we (the popup)
405 | // can access non-default audio devices when we list them.
406 | await setMicAccess("*://" + chrome.runtime.id + "/*", "allow");
407 | // Get the current list of audio devices.
408 | const deviceList = await navigator.mediaDevices.enumerateDevices();
409 | // Build the popup's device table.
410 | buildDeviceTable(deviceList);
411 | // Set the onClick handler for all buttons and disable
412 | // all but the "cancel" button, if tabError !== "".
413 | Array.from(document.getElementsByTagName("button")).forEach(function (e) {
414 | if ((tabError === "") || (e.id === "cancel")) {
415 | e.disabled = false;
416 | e.onclick = button_OnClick;
417 | } else {
418 | e.disabled = true;
419 | e.onclick = "";
420 | }
421 | });
422 | if (storageResult) {
423 | let now = Date.now() / 1000.0; // [seconds]
424 | // Enable animation only once every hour (3600 seconds)
425 | // Note that @media (prefers-reduced-motion) still disables animations entirely.
426 | if (!storageResult.lastAnimated || ((now - storageResult.lastAnimated) > 3600.0)) {
427 | document.querySelectorAll("header div").forEach(function(div) {
428 | div.classList.add("animation-enabled");
429 | });
430 | chrome.storage.local.set({"lastAnimated": now});
431 | }
432 | }
433 | }
434 |
435 | init();
436 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------