-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set reduce-lang origin correctly in service workers (#18756)
* Set reduce-lang origin correctly in service workers * tests
- Loading branch information
1 parent
8dd2be1
commit af5bef0
Showing
4 changed files
with
80 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
test/data/reduce-language/service-workers-accept-language.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<!-- Accept-Language HTTP header test from service worker --> | ||
<html> | ||
<head> | ||
<title></title> | ||
<meta charset="utf-8"> | ||
</head> | ||
<body> | ||
<script> | ||
navigator.serviceWorker.register('service-workers-accept-language.js') | ||
navigator.serviceWorker.onmessage = function (e) { | ||
document.title = e.data; // 'LOADED' or 'FAILED' | ||
}; | ||
navigator.serviceWorker.ready.then(function(registration) { | ||
if (!navigator.serviceWorker.controller) | ||
window.location.reload(); | ||
navigator.serviceWorker.controller.postMessage("fetch"); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
25 changes: 25 additions & 0 deletions
25
test/data/reduce-language/service-workers-accept-language.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) 2023 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
addEventListener('install', function(event) { | ||
event.waitUntil(self.skipWaiting()); // Activate worker immediately | ||
}); | ||
|
||
addEventListener('activate', function(event) { | ||
event.waitUntil(self.clients.claim()); // Become available to all pages | ||
}); | ||
|
||
addEventListener('message', (event) => { | ||
if (event.data == 'fetch') { | ||
fetch('/reduce-language/empty.json') | ||
.then(r => r.text()) | ||
.then(data => { | ||
event.source.postMessage('LOADED'); | ||
}) | ||
.catch((e) => { | ||
event.source.postMessage('FAILED'); | ||
}); | ||
} | ||
}); |