Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
disable webusb and bluetooth API
Browse files Browse the repository at this point in the history
neither are supported, but this will cause sites that check whether
they're supported to know more reliably that they aren't supproted.

fix #13374

Test Plan:
1. go to any site and open page console.
2. navigator.usb should be undefined
3. navigator.bluetooth should be undefined
  • Loading branch information
diracdeltas committed Mar 6, 2018
1 parent ab32f5e commit 027f15f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/extensions/brave/content/scripts/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })")
}
Expand Down
16 changes: 16 additions & 0 deletions test/contents/contentLoadingTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})
12 changes: 12 additions & 0 deletions test/fixtures/navigator.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<div id='bluetooth'>
testing...
</div>
<div id='webusb'>
testing...
</div>
<script>
bluetooth.innerText = navigator.bluetooth
webusb.innerText = navigator.usb
</script>
</html>

0 comments on commit 027f15f

Please sign in to comment.