diff --git a/.gitignore b/.gitignore
index 4a3f6f36..e637a8c0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -25,3 +25,4 @@ src/packages/excalidraw/types
src/packages/excalidraw/example/public/bundle.js
src/packages/excalidraw/example/public/excalidraw-assets-dev
src/packages/excalidraw/example/public/excalidraw.development.js
+coverage
diff --git a/dev-docs/docs/@excalidraw/excalidraw/faq.mdx b/dev-docs/docs/@excalidraw/excalidraw/faq.mdx
index 6f0fd30a..4684d6c7 100644
--- a/dev-docs/docs/@excalidraw/excalidraw/faq.mdx
+++ b/dev-docs/docs/@excalidraw/excalidraw/faq.mdx
@@ -4,6 +4,34 @@
No, Excalidraw package doesn't come with collaboration built in, since the implementation is specific to each host app. We expose APIs which you can use to communicate with Excalidraw which you can use to implement it. You can check our own implementation [here](https://github.com/excalidraw/excalidraw/blob/master/src/excalidraw-app/index.tsx). Here is a [detailed answer](https://github.com/excalidraw/excalidraw/discussions/3879#discussioncomment-1110524) on how you can achieve the same.
+### Turning off Aggressive Anti-Fingerprinting in Brave browser
+
+When *Aggressive Anti-Fingerprinting* is turned on, the `measureText` API breaks which in turn breaks the Text Elements in your drawings. Here is more [info](https://github.com/excalidraw/excalidraw/pull/6336) on the same.
+
+We strongly recommend turning it off. You can follow the steps below on how to do so.
+
+
+1. Open [excalidraw.com](https://excalidraw.com) in Brave and click on the **Shield** button
+![Shield button](../../assets/brave-shield.png)
+
+
+
+2. Once opened, look for **Aggressively Block Fingerprinting**
+
+![Aggresive block fingerprinting](../../assets/aggressive-block-fingerprint.png)
+
+3. Switch to **Block Fingerprinting**
+
+![Block filtering](../../assets/block-fingerprint.png)
+
+4. Thats all. All text elements should be fixed now 🎉
+
+
+
+If disabling this setting doesn't fix the display of text elements, please consider opening an [issue](https://github.com/excalidraw/excalidraw/issues/new) on our GitHub, or message us on [Discord](https://discord.gg/UexuTaE).
+
+
+
## Need help?
Check out the existing [Q&A](https://github.com/excalidraw/excalidraw/discussions?discussions_q=label%3Apackage%3Aexcalidraw). If you have any queries or need help, ask us [here](https://github.com/excalidraw/excalidraw/discussions?discussions_q=label%3Apackage%3Aexcalidraw).
diff --git a/dev-docs/docs/assets/aggressive-block-fingerprint.png b/dev-docs/docs/assets/aggressive-block-fingerprint.png
new file mode 100644
index 00000000..236a12db
Binary files /dev/null and b/dev-docs/docs/assets/aggressive-block-fingerprint.png differ
diff --git a/dev-docs/docs/assets/block-fingerprint.png b/dev-docs/docs/assets/block-fingerprint.png
new file mode 100644
index 00000000..bbbf4d26
Binary files /dev/null and b/dev-docs/docs/assets/block-fingerprint.png differ
diff --git a/dev-docs/docs/assets/brave-shield.png b/dev-docs/docs/assets/brave-shield.png
new file mode 100644
index 00000000..bbb12165
Binary files /dev/null and b/dev-docs/docs/assets/brave-shield.png differ
diff --git a/src/components/App.test.tsx b/src/components/App.test.tsx
new file mode 100644
index 00000000..baf25ab9
--- /dev/null
+++ b/src/components/App.test.tsx
@@ -0,0 +1,45 @@
+import ReactDOM from "react-dom";
+import * as Renderer from "../renderer/renderScene";
+import { reseed } from "../random";
+import { render, queryByTestId } from "../tests/test-utils";
+
+import ExcalidrawApp from "../excalidraw-app";
+
+const renderScene = jest.spyOn(Renderer, "renderScene");
+
+describe("Test ", () => {
+ beforeEach(async () => {
+ // Unmount ReactDOM from root
+ ReactDOM.unmountComponentAtNode(document.getElementById("root")!);
+ localStorage.clear();
+ renderScene.mockClear();
+ reseed(7);
+ });
+
+ it("should show error modal when using brave and measureText API is not working", async () => {
+ (global.navigator as any).brave = {
+ isBrave: {
+ name: "isBrave",
+ },
+ };
+
+ const originalContext = global.HTMLCanvasElement.prototype.getContext("2d");
+ //@ts-ignore
+ global.HTMLCanvasElement.prototype.getContext = (contextId) => {
+ return {
+ ...originalContext,
+ measureText: () => ({
+ width: 0,
+ }),
+ };
+ };
+
+ await render();
+ expect(
+ queryByTestId(
+ document.querySelector(".excalidraw-modal-container")!,
+ "brave-measure-text-error",
+ ),
+ ).toMatchSnapshot();
+ });
+});
diff --git a/src/components/App.tsx b/src/components/App.tsx
index a8240f12..714c349c 100644
--- a/src/components/App.tsx
+++ b/src/components/App.tsx
@@ -62,6 +62,7 @@ import {
GRID_SIZE,
IMAGE_RENDER_TIMEOUT,
isAndroid,
+ isBrave,
LINE_CONFIRM_THRESHOLD,
MAX_ALLOWED_FILE_BYTES,
MIME_TYPES,
@@ -267,6 +268,7 @@ import {
getContainerDims,
getContainerElement,
getTextBindableContainerAtPosition,
+ isMeasureTextSupported,
isValidTextContainer,
} from "../element/textElement";
import { isHittingElementNotConsideringBoundingBox } from "../element/collision";
@@ -285,6 +287,7 @@ import { actionToggleHandTool } from "../actions/actionCanvas";
import { jotaiStore } from "../jotai";
import { activeConfirmDialogAtom } from "./ActiveConfirmDialog";
import { actionCreateContainerFromText } from "../actions/actionBoundText";
+import BraveMeasureTextError from "./BraveMeasureTextError";
const deviceContextInitialValue = {
isSmScreen: false,
@@ -429,7 +432,6 @@ class App extends React.Component {
};
this.id = nanoid();
-
this.library = new Library(this);
if (excalidrawRef) {
const readyPromise =
@@ -711,6 +713,8 @@ class App extends React.Component {
const theme =
actionResult?.appState?.theme || this.props.theme || THEME.LIGHT;
let name = actionResult?.appState?.name ?? this.state.name;
+ const errorMessage =
+ actionResult?.appState?.errorMessage ?? this.state.errorMessage;
if (typeof this.props.viewModeEnabled !== "undefined") {
viewModeEnabled = this.props.viewModeEnabled;
}
@@ -726,7 +730,6 @@ class App extends React.Component {
if (typeof this.props.name !== "undefined") {
name = this.props.name;
}
-
this.setState(
(state) => {
// using Object.assign instead of spread to fool TS 4.2.2+ into
@@ -744,6 +747,7 @@ class App extends React.Component {
gridSize,
theme,
name,
+ errorMessage,
});
},
() => {
@@ -872,7 +876,6 @@ class App extends React.Component {
),
};
}
-
// FontFaceSet loadingdone event we listen on may not always fire
// (looking at you Safari), so on init we manually load fonts for current
// text elements on canvas, and rerender them once done. This also
@@ -1000,6 +1003,13 @@ class App extends React.Component {
} else {
this.updateDOMRect(this.initializeScene);
}
+
+ // note that this check seems to always pass in localhost
+ if (isBrave() && !isMeasureTextSupported()) {
+ this.setState({
+ errorMessage: ,
+ });
+ }
}
public componentWillUnmount() {
diff --git a/src/components/BraveMeasureTextError.tsx b/src/components/BraveMeasureTextError.tsx
new file mode 100644
index 00000000..8a4a71e4
--- /dev/null
+++ b/src/components/BraveMeasureTextError.tsx
@@ -0,0 +1,42 @@
+import { t } from "../i18n";
+const BraveMeasureTextError = () => {
+ return (
+
+
+ {t("errors.brave_measure_text_error.start")}
+
+ {t("errors.brave_measure_text_error.aggressive_block_fingerprint")}
+ {" "}
+ {t("errors.brave_measure_text_error.setting_enabled")}.
+
+
+ {t("errors.brave_measure_text_error.break")}{" "}
+
+ {t("errors.brave_measure_text_error.text_elements")}
+ {" "}
+ {t("errors.brave_measure_text_error.in_your_drawings")}.
+
+
+ {t("errors.brave_measure_text_error.strongly_recommend")}{" "}
+
+ {" "}
+ {t("errors.brave_measure_text_error.steps")}
+ {" "}
+ {t("errors.brave_measure_text_error.how")}.
+
+
+ {t("errors.brave_measure_text_error.disable_setting")}{" "}
+
+ {t("errors.brave_measure_text_error.issue")}
+ {" "}
+ {t("errors.brave_measure_text_error.write")}{" "}
+
+ {t("errors.brave_measure_text_error.discord")}
+
+ .
+
+
+ );
+};
+
+export default BraveMeasureTextError;
diff --git a/src/components/ErrorDialog.tsx b/src/components/ErrorDialog.tsx
index c1c78998..56c303c1 100644
--- a/src/components/ErrorDialog.tsx
+++ b/src/components/ErrorDialog.tsx
@@ -5,13 +5,13 @@ import { Dialog } from "./Dialog";
import { useExcalidrawContainer } from "./App";
export const ErrorDialog = ({
- message,
+ children,
onClose,
}: {
- message: string;
+ children?: React.ReactNode;
onClose?: () => void;
}) => {
- const [modalIsShown, setModalIsShown] = useState(!!message);
+ const [modalIsShown, setModalIsShown] = useState(!!children);
const { container: excalidrawContainer } = useExcalidrawContainer();
const handleClose = React.useCallback(() => {
@@ -32,7 +32,7 @@ export const ErrorDialog = ({
onCloseRequest={handleClose}
title={t("errorDialog.title")}
>
- {message}
+ {children}
)}
>
diff --git a/src/components/LayerUI.tsx b/src/components/LayerUI.tsx
index bea074d6..7103d3ad 100644
--- a/src/components/LayerUI.tsx
+++ b/src/components/LayerUI.tsx
@@ -364,10 +364,9 @@ const LayerUI = ({
{appState.isLoading && }
{appState.errorMessage && (
- setAppState({ errorMessage: null })}
- />
+ setAppState({ errorMessage: null })}>
+ {appState.errorMessage}
+
)}
{appState.openDialog === "help" && (
should show error modal when using brave and measureText API is not working 1`] = `
+
+
+ Looks like you are using Brave browser with the
+ Â
+
+ Aggressively Block Fingerprinting
+
+
+ setting enabled
+ .
+
+
+ This could result in breaking the
+
+
+ Text Elements
+
+
+ in your drawings
+ .
+
+
+ We strongly recommend disabling this setting. You can follow
+
+
+
+ these steps
+
+
+ on how to do so
+ .
+
+
+ If disabling this setting doesn't fix the display of text elements, please open an
+
+
+ issue
+
+
+ on our GitHub, or write us on
+
+
+ Discord
+
+ .
+
+
+`;
diff --git a/src/constants.ts b/src/constants.ts
index aa25667a..ef563e4a 100644
--- a/src/constants.ts
+++ b/src/constants.ts
@@ -12,6 +12,9 @@ export const isFirefox =
export const isChrome = navigator.userAgent.indexOf("Chrome") !== -1;
export const isSafari =
!isChrome && navigator.userAgent.indexOf("Safari") !== -1;
+// keeping function so it can be mocked in test
+export const isBrave = () =>
+ (navigator as any).brave?.isBrave?.name === "isBrave";
export const APP_NAME = "Excalidraw";
diff --git a/src/element/textElement.ts b/src/element/textElement.ts
index 18b96790..bdb11c9a 100644
--- a/src/element/textElement.ts
+++ b/src/element/textElement.ts
@@ -8,7 +8,13 @@ import {
NonDeletedExcalidrawElement,
} from "./types";
import { mutateElement } from "./mutateElement";
-import { BOUND_TEXT_PADDING, TEXT_ALIGN, VERTICAL_ALIGN } from "../constants";
+import {
+ BOUND_TEXT_PADDING,
+ DEFAULT_FONT_FAMILY,
+ DEFAULT_FONT_SIZE,
+ TEXT_ALIGN,
+ VERTICAL_ALIGN,
+} from "../constants";
import { MaybeTransformHandleType } from "./transformHandles";
import Scene from "../scene/Scene";
import { isTextElement } from ".";
@@ -794,3 +800,14 @@ export const getMaxContainerHeight = (container: ExcalidrawElement) => {
}
return height - BOUND_TEXT_PADDING * 2;
};
+
+export const isMeasureTextSupported = () => {
+ const width = getTextWidth(
+ DUMMY_TEXT,
+ getFontString({
+ fontSize: DEFAULT_FONT_SIZE,
+ fontFamily: DEFAULT_FONT_FAMILY,
+ }),
+ );
+ return width > 0;
+};
diff --git a/src/excalidraw-app/collab/Collab.tsx b/src/excalidraw-app/collab/Collab.tsx
index 30c9846c..e48484ab 100644
--- a/src/excalidraw-app/collab/Collab.tsx
+++ b/src/excalidraw-app/collab/Collab.tsx
@@ -838,10 +838,9 @@ class Collab extends PureComponent {
/>
)}
{errorMessage && (
- this.setState({ errorMessage: "" })}
- />
+ this.setState({ errorMessage: "" })}>
+ {errorMessage}
+
)}
>
);
diff --git a/src/excalidraw-app/index.tsx b/src/excalidraw-app/index.tsx
index 1c51637e..930143f9 100644
--- a/src/excalidraw-app/index.tsx
+++ b/src/excalidraw-app/index.tsx
@@ -673,10 +673,9 @@ const ExcalidrawWrapper = () => {
{excalidrawAPI && }
{errorMessage && (
- setErrorMessage("")}
- />
+ setErrorMessage("")}>
+ {errorMessage}
+
)}
);
diff --git a/src/locales/en.json b/src/locales/en.json
index f5ae003f..3021014e 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -120,7 +120,6 @@
"edit": "Edit line",
"exit": "Exit line editor"
},
-
"elementLock": {
"lock": "Lock",
"unlock": "Unlock",
@@ -206,7 +205,22 @@
"cannotResolveCollabServer": "Couldn't connect to the collab server. Please reload the page and try again.",
"importLibraryError": "Couldn't load library",
"collabSaveFailed": "Couldn't save to the backend database. If problems persist, you should save your file locally to ensure you don't lose your work.",
- "collabSaveFailed_sizeExceeded": "Couldn't save to the backend database, the canvas seems to be too big. You should save the file locally to ensure you don't lose your work."
+ "collabSaveFailed_sizeExceeded": "Couldn't save to the backend database, the canvas seems to be too big. You should save the file locally to ensure you don't lose your work.",
+ "brave_measure_text_error": {
+ "start": "Looks like you are using Brave browser with the",
+ "aggressive_block_fingerprint": "Aggressively Block Fingerprinting",
+ "setting_enabled": "setting enabled",
+ "break": "This could result in breaking the",
+ "text_elements": "Text Elements",
+ "in_your_drawings": "in your drawings",
+ "strongly_recommend": "We strongly recommend disabling this setting. You can follow",
+ "steps": "these steps",
+ "how": "on how to do so",
+ "disable_setting": " If disabling this setting doesn't fix the display of text elements, please open an",
+ "issue": "issue",
+ "write": "on our GitHub, or write us on",
+ "discord": "Discord"
+ }
},
"toolBar": {
"selection": "Selection",
diff --git a/src/types.ts b/src/types.ts
index e40476ea..09848df1 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -32,6 +32,7 @@ import type { FileSystemHandle } from "./data/filesystem";
import type { ALLOWED_IMAGE_MIME_TYPES, MIME_TYPES } from "./constants";
import { ContextMenuItems } from "./components/ContextMenu";
import { Merge, ForwardRef } from "./utility-types";
+import React from "react";
export type Point = Readonly;
@@ -101,7 +102,7 @@ export type AppState = {
} | null;
showWelcomeScreen: boolean;
isLoading: boolean;
- errorMessage: string | null;
+ errorMessage: React.ReactNode;
draggingElement: NonDeletedExcalidrawElement | null;
resizingElement: NonDeletedExcalidrawElement | null;
multiElement: NonDeleted | null;