When I change the theme of Home Assistant (by clicking radio button at user’s profile, demo), it calls fireEvent, if I read the source correctly.
I would like to call it from the browser’s console, but if I do
fireEvent(this, "settheme", { dark: true });
I get
VM1775:1 Uncaught ReferenceError: fireEvent is not defined
at <anonymous>:1:1
How can I access this function? Later I will call this function from the TamperMonkey script.
The following code is used in JS files:
https://raw.githubusercontent.com/home-assistant/frontend/20240906.0/src/common/dom/fire_event.ts:
declare global {
// eslint-disable-next-line
interface HASSDomEvents {}
}
export type ValidHassDomEvent = keyof HASSDomEvents;
...
export const fireEvent = <HassEvent extends ValidHassDomEvent>(
...
import { fireEvent } from "../../common/dom/fire_event";
2
Answers
The function should exist within in the ‘global’ scope, in a browser that’s
window
. So temporarily addingfireEvent
to thewindow
scope within the [ha-pick-theme-row.ts
I suppose] script should do the trick.After the page is loaded,
fireEvent
orwindow.fireEvent
should be available in the developer console.The GitHub link you’ve provided points to a TypeScript file. TypeScript cant run in browsers so you’ll need to transpile it to JavaScript first. You’ll also need to remove the "export" declaration for the fireEvent function; the "import" and "export" keywords can only be used in modules.
Your transpiled code:
You can then save the above into your browsers developer tools, under Sources > Snippets > New snippet. (Dev Tools Snippets).