forked from Archives/Athou_commafeed
correctly detect the extension if the hook is not used on the initial page
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
import { useEffect, useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
|
|
||||||
export const useBrowserExtension = () => {
|
export const useBrowserExtension = () => {
|
||||||
const [browserExtensionVersion, setBrowserExtensionVersion] = useState<string>()
|
// the extension will set the "browser-extension-installed" attribute on the root element
|
||||||
|
const [browserExtensionVersion, setBrowserExtensionVersion] = useState(
|
||||||
|
document.documentElement.getAttribute("browser-extension-installed")
|
||||||
|
)
|
||||||
|
|
||||||
// the extension will set the "browser-extension-installed" attribute on the root element, monitor it for changes
|
// monitor the attribute on the root element as it may change after the page was loaded
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const observer = new MutationObserver(mutations => {
|
const observer = new MutationObserver(mutations => {
|
||||||
mutations.forEach(mutation => {
|
mutations.forEach(mutation => {
|
||||||
|
|||||||
Reference in New Issue
Block a user