mirror of
https://github.com/bitwarden/browser.git
synced 2024-06-26 10:35:48 +02:00
[PM-8159] [PM-8158] [PM-8156] Swallow multiple offscreen document errors (#9195)
* Swallow multiple offscreen document errors The API has race issues with determining if an offscreen document exists (https://groups.google.com/a/chromium.org/g/chromium-extensions/c/s2Wp55bjySE/m/SnjJu1MdAAAJ). However, there are no negative effects of attempting to open multiple other than this throw. * Resolve circular dependency
This commit is contained in:
parent
4ccf920da8
commit
e55e3d5b9b
|
@ -380,7 +380,8 @@ export default class MainBackground {
|
||||||
const logoutCallback = async (expired: boolean, userId?: UserId) =>
|
const logoutCallback = async (expired: boolean, userId?: UserId) =>
|
||||||
await this.logout(expired, userId);
|
await this.logout(expired, userId);
|
||||||
|
|
||||||
this.logService = new ConsoleLogService(false);
|
const isDev = process.env.ENV === "development";
|
||||||
|
this.logService = new ConsoleLogService(isDev);
|
||||||
this.cryptoFunctionService = new WebCryptoFunctionService(self);
|
this.cryptoFunctionService = new WebCryptoFunctionService(self);
|
||||||
this.keyGenerationService = new KeyGenerationService(this.cryptoFunctionService);
|
this.keyGenerationService = new KeyGenerationService(this.cryptoFunctionService);
|
||||||
this.storageService = new BrowserLocalStorageService();
|
this.storageService = new BrowserLocalStorageService();
|
||||||
|
@ -399,7 +400,7 @@ export default class MainBackground {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
this.offscreenDocumentService = new DefaultOffscreenDocumentService();
|
this.offscreenDocumentService = new DefaultOffscreenDocumentService(this.logService);
|
||||||
|
|
||||||
this.platformUtilsService = new BackgroundPlatformUtilsService(
|
this.platformUtilsService = new BackgroundPlatformUtilsService(
|
||||||
this.messagingService,
|
this.messagingService,
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
import { mock } from "jest-mock-extended";
|
||||||
|
|
||||||
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
|
|
||||||
import { DefaultOffscreenDocumentService } from "./offscreen-document.service";
|
import { DefaultOffscreenDocumentService } from "./offscreen-document.service";
|
||||||
|
|
||||||
class TestCase {
|
class TestCase {
|
||||||
|
@ -21,6 +25,7 @@ describe.each([
|
||||||
new TestCase("synchronous callback", () => 42),
|
new TestCase("synchronous callback", () => 42),
|
||||||
new TestCase("asynchronous callback", () => Promise.resolve(42)),
|
new TestCase("asynchronous callback", () => Promise.resolve(42)),
|
||||||
])("DefaultOffscreenDocumentService %s", (testCase) => {
|
])("DefaultOffscreenDocumentService %s", (testCase) => {
|
||||||
|
const logService = mock<LogService>();
|
||||||
let sut: DefaultOffscreenDocumentService;
|
let sut: DefaultOffscreenDocumentService;
|
||||||
const reasons = [chrome.offscreen.Reason.TESTING];
|
const reasons = [chrome.offscreen.Reason.TESTING];
|
||||||
const justification = "justification is testing";
|
const justification = "justification is testing";
|
||||||
|
@ -37,7 +42,7 @@ describe.each([
|
||||||
callback = testCase.callback;
|
callback = testCase.callback;
|
||||||
chrome.offscreen = api;
|
chrome.offscreen = api;
|
||||||
|
|
||||||
sut = new DefaultOffscreenDocumentService();
|
sut = new DefaultOffscreenDocumentService(logService);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
|
|
||||||
export class DefaultOffscreenDocumentService implements DefaultOffscreenDocumentService {
|
export class DefaultOffscreenDocumentService implements DefaultOffscreenDocumentService {
|
||||||
private workerCount = 0;
|
private workerCount = 0;
|
||||||
|
|
||||||
constructor() {}
|
constructor(private logService: LogService) {}
|
||||||
|
|
||||||
async withDocument<T>(
|
async withDocument<T>(
|
||||||
reasons: chrome.offscreen.Reason[],
|
reasons: chrome.offscreen.Reason[],
|
||||||
|
@ -24,11 +26,21 @@ export class DefaultOffscreenDocumentService implements DefaultOffscreenDocument
|
||||||
}
|
}
|
||||||
|
|
||||||
private async create(reasons: chrome.offscreen.Reason[], justification: string): Promise<void> {
|
private async create(reasons: chrome.offscreen.Reason[], justification: string): Promise<void> {
|
||||||
await chrome.offscreen.createDocument({
|
try {
|
||||||
url: "offscreen-document/index.html",
|
await chrome.offscreen.createDocument({
|
||||||
reasons,
|
url: "offscreen-document/index.html",
|
||||||
justification,
|
reasons,
|
||||||
});
|
justification,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
// gobble multiple offscreen document creation errors
|
||||||
|
// TODO: remove this when the offscreen document service is fixed PM-8014
|
||||||
|
if (e.message === "Only a single offscreen document may be created.") {
|
||||||
|
this.logService.info("Ignoring offscreen document creation error.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async close(): Promise<void> {
|
private async close(): Promise<void> {
|
||||||
|
|
|
@ -195,9 +195,11 @@ const safeProviders: SafeProvider[] = [
|
||||||
}),
|
}),
|
||||||
safeProvider({
|
safeProvider({
|
||||||
provide: LogService,
|
provide: LogService,
|
||||||
useFactory: (platformUtilsService: PlatformUtilsService) =>
|
useFactory: () => {
|
||||||
new ConsoleLogService(platformUtilsService.isDev()),
|
const isDev = process.env.ENV === "development";
|
||||||
deps: [PlatformUtilsService],
|
return new ConsoleLogService(isDev);
|
||||||
|
},
|
||||||
|
deps: [],
|
||||||
}),
|
}),
|
||||||
safeProvider({
|
safeProvider({
|
||||||
provide: EnvironmentService,
|
provide: EnvironmentService,
|
||||||
|
@ -286,7 +288,7 @@ const safeProviders: SafeProvider[] = [
|
||||||
safeProvider({
|
safeProvider({
|
||||||
provide: OffscreenDocumentService,
|
provide: OffscreenDocumentService,
|
||||||
useClass: DefaultOffscreenDocumentService,
|
useClass: DefaultOffscreenDocumentService,
|
||||||
deps: [],
|
deps: [LogService],
|
||||||
}),
|
}),
|
||||||
safeProvider({
|
safeProvider({
|
||||||
provide: PlatformUtilsService,
|
provide: PlatformUtilsService,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user