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:
parent
6fd81fa4d0
commit
ac633687ec
@ -20,6 +20,7 @@ export interface OffscreenDocument {
|
||||
}
|
||||
|
||||
export abstract class OffscreenDocumentService {
|
||||
abstract offscreenApiSupported(): boolean;
|
||||
abstract withDocument<T>(
|
||||
reasons: chrome.offscreen.Reason[],
|
||||
justification: string,
|
||||
|
@ -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, () => {});
|
||||
|
@ -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,
|
||||
|
@ -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"),
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user