Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions addon-api/common/Self.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Listenable from "./Listenable.js";
import { isFirefox } from "../../libraries/common/cs/detect-browser.js";

/**
* Represents information about the addon.
Expand All @@ -13,8 +14,7 @@ export default class Self extends Listenable {
this._addonId = info.id; // In order to receive fireEvent messages from background
this.id = info.id;
this._addonObj = addonObj;
// catches both Chrome and Chromium
this.browser = /Chrom/.test(navigator.userAgent) ? "chrome" : "firefox";
this.browser = isFirefox() ? "firefox" : "chrome";
this.disabled = false;
this.addEventListener("disabled", () => (this.disabled = true));
this.addEventListener("reenabled", () => (this.disabled = false));
Expand Down
6 changes: 4 additions & 2 deletions addons/gamepad/gamepadlib.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isFirefox } from "../../libraries/common/cs/detect-browser.js";

let console = window.console;

/*
Expand Down Expand Up @@ -652,7 +654,7 @@ GamepadLib.browserHasBrokenGamepadAPI = () => {
// Firefox on Linux before version 123 has a broken gamepad API that results in strange and unusable mappings
// https://bugzilla.mozilla.org/show_bug.cgi?id=1680982
// https://bugzilla.mozilla.org/show_bug.cgi?id=1643835
if (navigator.userAgent.includes("Firefox") && navigator.userAgent.includes("Linux")) {
if (isFirefox() && navigator.userAgent.includes("Linux")) {
const agentMatch = navigator.userAgent.match(/Firefox\/(\d+)/);
// If we couldn't find the version number, we'll assume that this is some distant future version of
// Firefox that we just can't comprehend with the technology of today. Surely gamepad will work well
Expand All @@ -662,7 +664,7 @@ GamepadLib.browserHasBrokenGamepadAPI = () => {
}
// Firefox on macOS has other bugs that result in strange and unusable mappings
// eg. https://bugzilla.mozilla.org/show_bug.cgi?id=1434408
if (navigator.userAgent.includes("Firefox") && navigator.userAgent.includes("Mac OS")) {
if (isFirefox() && navigator.userAgent.includes("Mac OS")) {
return true;
}
return false;
Expand Down
4 changes: 3 additions & 1 deletion background/firefox-localhost-support.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
if (typeof browser === "object" && chrome.scripting) {
import { isFirefox } from "../libraries/common/cs/detect-browser.js";

if (isFirefox() && chrome.scripting) {
const manifest = chrome.runtime.getManifest();
const manifestScripts = manifest.content_scripts.filter((script) =>
script.matches.includes("http://localhost:8601/*")
Expand Down
4 changes: 2 additions & 2 deletions background/handle-auth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { startCache } from "./message-cache.js";
import { openMessageCache } from "../libraries/common/message-cache.js";
import { purgeDatabase } from "../addons/scratch-notifier/notifier.js";
import { isFirefox } from "../libraries/common/cs/detect-browser.js";

async function getDefaultStoreId() {
const CHROME_DEFAULT = "0";
Expand Down Expand Up @@ -168,8 +169,7 @@ function notify(cookie) {
if (cookie.name === "scratchlanguage") return;
const storeId = cookie.storeId;
const cond = {};
if (typeof browser === "object") {
// Firefox-exclusive.
if (isFirefox()) {
cond.cookieStoreId = storeId;
}
// On Chrome this can cause unnecessary session re-fetch, but there should be
Expand Down
5 changes: 3 additions & 2 deletions background/handle-clipboard.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isFirefox } from "../libraries/common/cs/detect-browser.js";

const dataURLToArrayBuffer = function (dataURL) {
const byteString = atob(dataURL.split(",")[1]);
const arrayBuffer = new ArrayBuffer(byteString.length);
Expand All @@ -8,8 +10,7 @@ const dataURLToArrayBuffer = function (dataURL) {
return arrayBuffer;
};

if (typeof browser !== "undefined") {
// Firefox
if (isFirefox()) {
browser.runtime.onMessage.addListener(function (request) {
if (request.clipboardDataURL && browser && browser.clipboard && browser.clipboard.setImageData) {
const arrayBuffer = dataURLToArrayBuffer(request.clipboardDataURL);
Expand Down
5 changes: 3 additions & 2 deletions background/imports/util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { isFirefox } from "../../libraries/common/cs/detect-browser.js";

// REMINDER: update similar code at /webpages/settings/index.js
const browserLevelPermissions = ["notifications"];
if (typeof browser !== "undefined") {
// Firefox only
if (isFirefox()) {
if (typeof Clipboard.prototype.write !== "function") {
// Firefox 109-126 only
browserLevelPermissions.push("clipboardWrite");
Expand Down
3 changes: 3 additions & 0 deletions libraries/common/cs/detect-browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function isFirefox() {
return typeof new Error().fileName !== "undefined";
}
4 changes: 3 additions & 1 deletion libraries/common/notification-util.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isFirefox } from "./cs/detect-browser.js";

let id = 0;

export default function create(opts) {
Expand All @@ -7,7 +9,7 @@ export default function create(opts) {
if (scratchAddons.muted) return Promise.resolve(null);
const notifId = `${opts.base}__${Date.now()}_${id++}`;
let newOpts;
if (!/Chrom/.test(navigator.userAgent)) {
if (isFirefox()) {
newOpts = JSON.parse(JSON.stringify(opts));
// On Firefox, remove notification properties that throw.
delete newOpts.buttons;
Expand Down
7 changes: 3 additions & 4 deletions webpages/settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import exampleManifest from "./data/example-manifest.js";
import fuseOptions from "./data/fuse-options.js";
import globalTheme from "../../libraries/common/global-theme.js";
import { deserializeSettings, serializeSettings } from "./settings-utils.js";
import { isFirefox } from "../../libraries/common/cs/detect-browser.js";

let isIframe = false;
if (window.parent !== window) {
Expand Down Expand Up @@ -64,8 +65,7 @@ let fuse;

// REMINDER: update similar code at /background/imports/util.js
const browserLevelPermissions = ["notifications"];
if (typeof browser !== "undefined") {
// Firefox only
if (isFirefox()) {
if (typeof Clipboard.prototype.write !== "function") {
// Firefox 109-126 only
browserLevelPermissions.push("clipboardWrite");
Expand Down Expand Up @@ -385,8 +385,7 @@ let fuse;
// Autofocus search bar in iframe mode for both browsers
// autofocus attribute only works in Chrome for us, so
// we also manually focus on Firefox, even in fullscreen
if (isIframe || typeof browser !== "undefined")
setTimeout(() => document.getElementById("searchBox")?.focus(), 0);
if (isIframe || isFirefox()) setTimeout(() => document.getElementById("searchBox")?.focus(), 0);

const exampleAddonListItem = {
// Need to specify all used properties for reactivity!
Expand Down