hass-browser_mod icon indicating copy to clipboard operation
hass-browser_mod copied to clipboard

popup run from script via fire-dom-event opens on all browsers

Open dziadeck47 opened this issue 1 year ago • 4 comments

My Home Assistant version: 2022.9.2

What I am doing:

I wrote a popup script to the side and want to launch it from dashboard via:

action: fire-dom-event browser_mod: service: script.test_popup data: browser_id: THIS

script looks as follows: sequence:

  • service: browser_mod.popup data: title: The title right_button: Right button content: The content

What I expected to happen:

As per documentation I expect a popup to show up only on browser I click from

What happened instead:

Opens up on 2 browsers. Same when I input an existing browserID in the card. Inputting the explicit browserid directly in the script works though so it looks like it is not passed thru from the dashboard

Minimal steps to reproduce:

# The least amount of code or steps possible to reproduce my error

# Put your code/steps here

Error messages from the browser console:

// Select everything from the browser console and copy it

// Paste it here

By replacing the space in the checkboxes ([ ]) with an X below, I indicate that I:

  • [x] Understand that this is a channel for reporting bugs, not a support forum (https://community.home-assistant.io/).

  • [x] Have made sure I am using the latest version of the plugin.

  • [x] Have followed the troubleshooting steps of the "Common Problems" section of https://github.com/thomasloven/hass-config/wiki/Lovelace-Plugins.

  • [x] Understand that leaving one or more boxes unticked or failure to follow the template above may increase the time required to handle my bug-report, or cause it to be closed without further action.

dziadeck47 avatar Sep 13 '22 00:09 dziadeck47

AFAICT, the fire-dom-event action you wrote passes a browser_id variable to your script, which does not use it at all. Shouldn't it read like so instead ? (note the added last line)

sequence:
  - service: browser_mod.popup
    data:
      title: The title
      right_button: Right button
      content: The content
      browser_id: "{{ browser_id }}"

Beware that variables in home assistant are explicitly passed and more akin to key-value arguments than environment variables (that are often inherited).

FrnchFrgg avatar Sep 13 '22 15:09 FrnchFrgg

Works like charm, thanks! I tried a similar approach, only forgot the quotation marks ( used browser_id: {{ browser_id }} which did not of course work)

I think the documentation just needs an update as it claims that:

Browser call (...) is when the service is called from a dashboard fire-dom-event action, as a part of a browser_mod.sequence call or as a browser_mod.popup _action. when no target (browser_id) is specified(...) browser call will perform the service on THE CURRENT BROWSER, i.e. the browser it was called from

which is true for a direct browser_mod.popup _action but not when running a script from e.g. browser_mod.sequence

dziadeck47 avatar Sep 13 '22 17:09 dziadeck47

This is expected, since anything that is fire-dom-event, including browser_mod.sequence, takes place in the frontend, that is a « browser call ». A script, even when initially called from a browser call, takes place in the backend, and is thus subject to all the limitations of backend browser_mod services (needs the browser to be registered, needs explicit browser_id argument to target a specific one, etc.)

FrnchFrgg avatar Sep 13 '22 18:09 FrnchFrgg

Works like charm The downside is the browser_id: is not an argument which can be set up in the script visual editor When I set up the script the "Browser mod: popup" service can be filled in beatifully in the visual editor, from title to style. When I add "browser_id:" manually to yaml it all goes bust and shows the pure yaml instead ("Visual editor is not supported for this configuration"). Is there a way to add "browser_id:" to the service definition so it can be filled in the UI rather than yaml?

dziadeck47 avatar Sep 19 '22 21:09 dziadeck47