Skip to content

Commit

Permalink
fix: unify code for all browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
vitonsky committed Jun 12, 2024
1 parent 2c1c5b8 commit b2df227
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 20 deletions.
1 change: 1 addition & 0 deletions manifests/chromium.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"manifest_version": 3,
"update_url": "https://translate-tools.github.io/linguist/chromium_updates.xml",
"background": {
"service_worker": "background.worker.js",
Expand Down
2 changes: 1 addition & 1 deletion manifests/firefox.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"manifest_version": 2,
"permissions": ["storage", "<all_urls>"],
"permissions": ["<all_urls>"],
"web_accessible_resources": [
"common.css",
"thirdparty/bergamot/bergamot-translator-worker.wasm",
Expand Down
1 change: 0 additions & 1 deletion manifests/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"manifest_version": 3,
"default_locale": "en",
"name": "__MSG_ext_name__",
"description": "__MSG_ext_description__",
Expand Down
4 changes: 2 additions & 2 deletions src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createEvent, createStore, Store } from 'effector';
import browser from 'webextension-polyfill';

import { defaultConfig } from '../config';
import { isBackgroundContext, isChromium } from '../lib/browser';
import { isBackgroundContext, isChromium, isFirefox } from '../lib/browser';
import { AppThemeControl } from '../lib/browser/AppThemeControl';
import { getAllTabs } from '../lib/browser/tabs';
import { TextTranslatorStorage } from '../pages/popup/tabs/TextTranslator/TextTranslator.utils/TextTranslatorStorage';
Expand Down Expand Up @@ -113,7 +113,7 @@ export class App {

private async setupRequestHandlers() {
// Prevent run it again on other pages, such as options page
if (isBackgroundContext()) {
if (!isFirefox() || isBackgroundContext()) {
requestHandlers.forEach((factory) => {
factory({
config: this.config,
Expand Down
25 changes: 10 additions & 15 deletions src/offscreen-documents/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@
import { customTranslatorsFactory } from '../../requests/offscreen/customTranslators';

// TODO: add types validation between all requests

export const runTranslatorsSandbox = () => {
console.log('runTranslatorsSandbox is in run');

document.addEventListener('DOMContentLoaded', async () => {
console.log('Main is run');
customTranslatorsFactory();
};
// document.addEventListener('DOMContentLoaded', async () => {
// console.log('Main is run');
// // const iframe1 = document.createElement('iframe', {});
// // iframe1.src = '/offscreen-documents/worker/worker.html';
// // iframe1.setAttribute(
// // 'sandbox',
// // 'allow-same-origin allow-scripts allow-popups allow-forms',
// // );
// // document.body.appendChild(iframe1);

// });
const workerIframe = document.createElement('iframe', {});
workerIframe.src = '/offscreen-documents/worker/worker.html';
workerIframe.setAttribute(
'sandbox',
'allow-same-origin allow-scripts allow-popups allow-forms',
);
document.body.appendChild(workerIframe);
});
3 changes: 2 additions & 1 deletion src/requests/offscreen/customTranslators/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Connection, connectToChild } from 'penpal';

import { isChromium } from '../../../lib/browser';
import { TranslatorWorkerApi } from '../../../offscreen-documents/translator';
import { buildBackendRequest } from '../../utils/requestBuilder';

Expand Down Expand Up @@ -38,7 +39,7 @@ export const customTranslatorCreate = buildBackendRequest<
// Connect controller
const controller = connectToChild<TranslatorWorkerApi>({
iframe,
// childOrigin: '*',
childOrigin: isChromium() ? '*' : undefined,
// timeout: 5000,
debug: true,
});
Expand Down

0 comments on commit b2df227

Please sign in to comment.