From 027f15fa43be6cbdf97f377ff5ea9d67e944ce5e Mon Sep 17 00:00:00 2001 From: yan Date: Fri, 2 Mar 2018 14:05:32 -0800 Subject: [PATCH] disable webusb and bluetooth API neither are supported, but this will cause sites that check whether they're supported to know more reliably that they aren't supproted. fix https://github.com/brave/browser-laptop/issues/13374 Test Plan: 1. go to any site and open page console. 2. navigator.usb should be undefined 3. navigator.bluetooth should be undefined --- .../brave/content/scripts/navigator.js | 5 +++++ test/contents/contentLoadingTest.js | 16 ++++++++++++++++ test/fixtures/navigator.html | 12 ++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 test/fixtures/navigator.html diff --git a/app/extensions/brave/content/scripts/navigator.js b/app/extensions/brave/content/scripts/navigator.js index 261485ca4a2..02bf81fe8af 100644 --- a/app/extensions/brave/content/scripts/navigator.js +++ b/app/extensions/brave/content/scripts/navigator.js @@ -12,6 +12,11 @@ chrome.webFrame.setGlobal("navigator.getBattery", function () { return new Promise((resolve, reject) => { reject(new Error('navigator.getBattery not supported.')) }) }) +// bluetooth is not currently supported +executeScript("window.Navigator.prototype.__defineGetter__('bluetooth', () => { return undefined })") +// webusb also not supported yet +executeScript("window.Navigator.prototype.__defineGetter__('usb', () => { return undefined })") + if (chrome.contentSettings.doNotTrack == 'allow') { executeScript("window.Navigator.prototype.__defineGetter__('doNotTrack', () => { return 1 })") } diff --git a/test/contents/contentLoadingTest.js b/test/contents/contentLoadingTest.js index 84906d71275..f9c637673d3 100644 --- a/test/contents/contentLoadingTest.js +++ b/test/contents/contentLoadingTest.js @@ -51,4 +51,20 @@ describe('content loading', function () { .windowByUrl(Brave.browserWindowUrl) .waitForTextValue('[data-test-id="tabTitle"]', 'fail') }) + + it('does not support bluetooth API', function * () { + const page1 = Brave.fixtureUrl('navigator.html') + yield this.app.client + .tabByIndex(0) + .url(page1) + .waitForTextValue('#bluetooth', 'undefined') + }) + + it('does not support webusb API', function * () { + const page1 = Brave.fixtureUrl('navigator.html') + yield this.app.client + .tabByIndex(0) + .url(page1) + .waitForTextValue('#webusb', 'undefined') + }) }) diff --git a/test/fixtures/navigator.html b/test/fixtures/navigator.html new file mode 100644 index 00000000000..ee1763dc795 --- /dev/null +++ b/test/fixtures/navigator.html @@ -0,0 +1,12 @@ + +
+ testing... +
+
+ testing... +
+ +