1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-25 12:15:18 +01:00

[PM-8276] Edge Cannot Copy to Clipboard When Using Mv3 (#9266)

* [PM-8276] Edge Cannot Copy to Clipboard When Using Mv3

* [PM-8276] Fixing jest tests

* [PM-8276] Fixing jest tests

* [PM-8276] Fixing jest tests
This commit is contained in:
Cesar Gonzalez 2024-05-20 14:37:55 -05:00 committed by GitHub
parent 6fd81fa4d0
commit ac633687ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 18 additions and 9 deletions

View File

@ -20,6 +20,7 @@ export interface OffscreenDocument {
}
export abstract class OffscreenDocumentService {
abstract offscreenApiSupported(): boolean;
abstract withDocument<T>(
reasons: chrome.offscreen.Reason[],
justification: string,

View File

@ -49,6 +49,12 @@ describe.each([
jest.resetAllMocks();
});
describe("offscreenApiSupported", () => {
it("indicates whether the offscreen API is supported", () => {
expect(sut.offscreenApiSupported()).toBe(true);
});
});
describe("withDocument", () => {
it("creates a document when none exists", async () => {
await sut.withDocument(reasons, justification, () => {});

View File

@ -1,10 +1,16 @@
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
export class DefaultOffscreenDocumentService implements DefaultOffscreenDocumentService {
import { OffscreenDocumentService } from "./abstractions/offscreen-document";
export class DefaultOffscreenDocumentService implements OffscreenDocumentService {
private workerCount = 0;
constructor(private logService: LogService) {}
offscreenApiSupported(): boolean {
return typeof chrome.offscreen !== "undefined";
}
async withDocument<T>(
reasons: chrome.offscreen.Reason[],
justification: string,

View File

@ -229,9 +229,7 @@ describe("Browser Utils Service", () => {
it("copies the passed text using the offscreen document if the extension is using manifest v3", async () => {
const text = "test";
jest
.spyOn(browserPlatformUtilsService, "getDevice")
.mockReturnValue(DeviceType.ChromeExtension);
offscreenDocumentService.offscreenApiSupported.mockReturnValue(true);
getManifestVersionSpy.mockReturnValue(3);
browserPlatformUtilsService.copyToClipboard(text);
@ -304,9 +302,7 @@ describe("Browser Utils Service", () => {
});
it("reads the clipboard text using the offscreen document", async () => {
jest
.spyOn(browserPlatformUtilsService, "getDevice")
.mockReturnValue(DeviceType.ChromeExtension);
offscreenDocumentService.offscreenApiSupported.mockReturnValue(true);
getManifestVersionSpy.mockReturnValue(3);
offscreenDocumentService.withDocument.mockImplementationOnce((_, __, callback) =>
Promise.resolve("test"),

View File

@ -243,7 +243,7 @@ export abstract class BrowserPlatformUtilsService implements PlatformUtilsServic
text = "\u0000";
}
if (this.isChrome() && BrowserApi.isManifestVersion(3)) {
if (BrowserApi.isManifestVersion(3) && this.offscreenDocumentService.offscreenApiSupported()) {
void this.triggerOffscreenCopyToClipboard(text).then(handleClipboardWriteCallback);
return;
@ -268,7 +268,7 @@ export abstract class BrowserPlatformUtilsService implements PlatformUtilsServic
return await SafariApp.sendMessageToApp("readFromClipboard");
}
if (this.isChrome() && BrowserApi.isManifestVersion(3)) {
if (BrowserApi.isManifestVersion(3) && this.offscreenDocumentService.offscreenApiSupported()) {
return await this.triggerOffscreenReadFromClipboard();
}