mirror of
https://github.com/bitwarden/browser.git
synced 2024-10-06 05:28:51 +02: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 {
|
export abstract class OffscreenDocumentService {
|
||||||
|
abstract offscreenApiSupported(): boolean;
|
||||||
abstract withDocument<T>(
|
abstract withDocument<T>(
|
||||||
reasons: chrome.offscreen.Reason[],
|
reasons: chrome.offscreen.Reason[],
|
||||||
justification: string,
|
justification: string,
|
||||||
|
@ -49,6 +49,12 @@ describe.each([
|
|||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("offscreenApiSupported", () => {
|
||||||
|
it("indicates whether the offscreen API is supported", () => {
|
||||||
|
expect(sut.offscreenApiSupported()).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("withDocument", () => {
|
describe("withDocument", () => {
|
||||||
it("creates a document when none exists", async () => {
|
it("creates a document when none exists", async () => {
|
||||||
await sut.withDocument(reasons, justification, () => {});
|
await sut.withDocument(reasons, justification, () => {});
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
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;
|
private workerCount = 0;
|
||||||
|
|
||||||
constructor(private logService: LogService) {}
|
constructor(private logService: LogService) {}
|
||||||
|
|
||||||
|
offscreenApiSupported(): boolean {
|
||||||
|
return typeof chrome.offscreen !== "undefined";
|
||||||
|
}
|
||||||
|
|
||||||
async withDocument<T>(
|
async withDocument<T>(
|
||||||
reasons: chrome.offscreen.Reason[],
|
reasons: chrome.offscreen.Reason[],
|
||||||
justification: string,
|
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 () => {
|
it("copies the passed text using the offscreen document if the extension is using manifest v3", async () => {
|
||||||
const text = "test";
|
const text = "test";
|
||||||
jest
|
offscreenDocumentService.offscreenApiSupported.mockReturnValue(true);
|
||||||
.spyOn(browserPlatformUtilsService, "getDevice")
|
|
||||||
.mockReturnValue(DeviceType.ChromeExtension);
|
|
||||||
getManifestVersionSpy.mockReturnValue(3);
|
getManifestVersionSpy.mockReturnValue(3);
|
||||||
|
|
||||||
browserPlatformUtilsService.copyToClipboard(text);
|
browserPlatformUtilsService.copyToClipboard(text);
|
||||||
@ -304,9 +302,7 @@ describe("Browser Utils Service", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("reads the clipboard text using the offscreen document", async () => {
|
it("reads the clipboard text using the offscreen document", async () => {
|
||||||
jest
|
offscreenDocumentService.offscreenApiSupported.mockReturnValue(true);
|
||||||
.spyOn(browserPlatformUtilsService, "getDevice")
|
|
||||||
.mockReturnValue(DeviceType.ChromeExtension);
|
|
||||||
getManifestVersionSpy.mockReturnValue(3);
|
getManifestVersionSpy.mockReturnValue(3);
|
||||||
offscreenDocumentService.withDocument.mockImplementationOnce((_, __, callback) =>
|
offscreenDocumentService.withDocument.mockImplementationOnce((_, __, callback) =>
|
||||||
Promise.resolve("test"),
|
Promise.resolve("test"),
|
||||||
|
@ -243,7 +243,7 @@ export abstract class BrowserPlatformUtilsService implements PlatformUtilsServic
|
|||||||
text = "\u0000";
|
text = "\u0000";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isChrome() && BrowserApi.isManifestVersion(3)) {
|
if (BrowserApi.isManifestVersion(3) && this.offscreenDocumentService.offscreenApiSupported()) {
|
||||||
void this.triggerOffscreenCopyToClipboard(text).then(handleClipboardWriteCallback);
|
void this.triggerOffscreenCopyToClipboard(text).then(handleClipboardWriteCallback);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -268,7 +268,7 @@ export abstract class BrowserPlatformUtilsService implements PlatformUtilsServic
|
|||||||
return await SafariApp.sendMessageToApp("readFromClipboard");
|
return await SafariApp.sendMessageToApp("readFromClipboard");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isChrome() && BrowserApi.isManifestVersion(3)) {
|
if (BrowserApi.isManifestVersion(3) && this.offscreenDocumentService.offscreenApiSupported()) {
|
||||||
return await this.triggerOffscreenReadFromClipboard();
|
return await this.triggerOffscreenReadFromClipboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user