[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) =>
|
||||
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.keyGenerationService = new KeyGenerationService(this.cryptoFunctionService);
|
||||
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.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";
|
||||
|
||||
class TestCase {
|
||||
|
@ -21,6 +25,7 @@ describe.each([
|
|||
new TestCase("synchronous callback", () => 42),
|
||||
new TestCase("asynchronous callback", () => Promise.resolve(42)),
|
||||
])("DefaultOffscreenDocumentService %s", (testCase) => {
|
||||
const logService = mock<LogService>();
|
||||
let sut: DefaultOffscreenDocumentService;
|
||||
const reasons = [chrome.offscreen.Reason.TESTING];
|
||||
const justification = "justification is testing";
|
||||
|
@ -37,7 +42,7 @@ describe.each([
|
|||
callback = testCase.callback;
|
||||
chrome.offscreen = api;
|
||||
|
||||
sut = new DefaultOffscreenDocumentService();
|
||||
sut = new DefaultOffscreenDocumentService(logService);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
|
||||
export class DefaultOffscreenDocumentService implements DefaultOffscreenDocumentService {
|
||||
private workerCount = 0;
|
||||
|
||||
constructor() {}
|
||||
constructor(private logService: LogService) {}
|
||||
|
||||
async withDocument<T>(
|
||||
reasons: chrome.offscreen.Reason[],
|
||||
|
@ -24,11 +26,21 @@ export class DefaultOffscreenDocumentService implements DefaultOffscreenDocument
|
|||
}
|
||||
|
||||
private async create(reasons: chrome.offscreen.Reason[], justification: string): Promise<void> {
|
||||
await chrome.offscreen.createDocument({
|
||||
url: "offscreen-document/index.html",
|
||||
reasons,
|
||||
justification,
|
||||
});
|
||||
try {
|
||||
await chrome.offscreen.createDocument({
|
||||
url: "offscreen-document/index.html",
|
||||
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> {
|
||||
|
|
|
@ -195,9 +195,11 @@ const safeProviders: SafeProvider[] = [
|
|||
}),
|
||||
safeProvider({
|
||||
provide: LogService,
|
||||
useFactory: (platformUtilsService: PlatformUtilsService) =>
|
||||
new ConsoleLogService(platformUtilsService.isDev()),
|
||||
deps: [PlatformUtilsService],
|
||||
useFactory: () => {
|
||||
const isDev = process.env.ENV === "development";
|
||||
return new ConsoleLogService(isDev);
|
||||
},
|
||||
deps: [],
|
||||
}),
|
||||
safeProvider({
|
||||
provide: EnvironmentService,
|
||||
|
@ -286,7 +288,7 @@ const safeProviders: SafeProvider[] = [
|
|||
safeProvider({
|
||||
provide: OffscreenDocumentService,
|
||||
useClass: DefaultOffscreenDocumentService,
|
||||
deps: [],
|
||||
deps: [LogService],
|
||||
}),
|
||||
safeProvider({
|
||||
provide: PlatformUtilsService,
|
||||
|
|
Loading…
Reference in New Issue