Skip to content

Commit

Permalink
fix: sendResponse not working in firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
linonetwo committed Oct 12, 2023
1 parent 002630e commit 38d0f6d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Then run the following:
1. Go to the browser address bar and type [about:debugging#/runtime/this-firefox](about:debugging#/runtime/this-firefox) (not the [about:addons](about:addons))
1. Click on the `Load Temporary Add-on` list item after click on setting button.
1. Select your `dist-firefox` folder in the project root.
1. [Debug popup in firefox](https://firefox-source-docs.mozilla.org/devtools-user/browser_toolbox/index.html)

### Other Commands

Expand Down
1 change: 0 additions & 1 deletion src/content/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export function Content() {
const { t } = useTranslation();
const [isSelecting, setIsSelecting] = useState(false);
const { parseReadability } = useReadability();

const [selectedElement, setSelectedElement] = useState<HTMLElement | null>(null);
useMessaging({ setIsSelecting, parseReadability, selectedElement });
const { updateSelector } = useSelectorGenerator();
Expand Down
11 changes: 7 additions & 4 deletions src/content/hooks/useMessaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ export function useMessaging(
if (parameter.selectedElement === null) return;
const text = parameter.selectedElement.textContent ?? '';
const html = parameter.selectedElement.outerHTML;
sendResponse({ action: ITabActions.startClippingResponse, text, html } satisfies IStartClippingResponseMessage);
break;
const response = { action: ITabActions.startClippingResponse, text, html } satisfies IStartClippingResponseMessage;
sendResponse(response);
// return the response instead of `sendResponse`, otherwise response will be `undefined` in firefox. In Chrome, `sendResponse` works fine.
return response;
}
case ITabActions.getReadability: {
const article = parameter.parseReadability();
// Get the current webpage URL
const url = window.location.href;
sendResponse({ action: ITabActions.getReadabilityResponse, article, url });
break;
const response = { action: ITabActions.getReadabilityResponse, article, url };
sendResponse(response);
return response;
}
}
});
Expand Down

0 comments on commit 38d0f6d

Please sign in to comment.