Floating Firefox Extension's Windows

Regular rules do not work with Firefox extensions because Firefox sets the title of the window after spawning it.

The workaround for this is using Hyprland’s events:

hl.on("window.title", function(w)
    if string.find(w.title, "Extension: (AliasVault)", nil, true ) then
        local monitor = hl.get_active_monitor()
        if monitor == nil then
            return
        end

        local win_size = {
            width = 500,
            height = 530
        }
        --[[ local win_pos = {
            x = monitor.width * 0.5 - win_size.width * 0.5,
            y = monitor.height * 0.5 - win_size.height * 0.5
        } --]]

        hl.dispatch(
            hl.dsp.window.float({
                action = "enable",
                window = w
            })
        )
        hl.dispatch(
            hl.dsp.window.resize({
                x = win_size.width,
                y = win_size.height,
                relative = false,
                window = w
            })
        )
        --[[ hl.dispatch(
            hl.dsp.window.move({
                x = win_pos.x,
                y = win_pos.y,
                relative = false,
                window = w
            })
        ) --]]
        hl.dispatch(hl.dsp.window.center({ window = w }))
    end
end)

You can use the commented section if you would like the window somewhere specific.

That is all, cheers.

After trying unsuccessfully various methods including timers to script a solution to:

I applied your function and it no workie for the noscript window.

This is just a curiosity as I don’t use Firefox for other than testing.

That is odd, I have tested this with Bitwarden, AliasVault and some others and all of them worked. Does it work for other windows on your side?

NoScript is certainly more finicky.

I ended up writing a rule that tames NoScript.

hl.on("window.open", function(w)
    if w.class ~= "firefox" then return end
    if w.initial_title ~= "Mozilla Firefox" then return end

    local ff_windows = hl.get_windows({ class = "firefox" })
    if #ff_windows <= 1 then return end

    hl.dispatch(hl.dsp.window.float({ action = "set", window = w }))

    local sub
    sub = hl.on("window.title", function(tw)
        if tw.address ~= w.address then return end
        if tw.title == ""
            or tw.title == "Mozilla Firefox"
            or tw.title == "about:blank"
            or tw.title:match("^about:.*Mozilla Firefox$") then return end

        sub:remove()

        if tw.title:match("^Extension: %(NoScript%)") then
            hl.dispatch(hl.dsp.window.resize({ x = 800, y = 600, window = tw }))
            hl.dispatch(hl.dsp.window.center({ window = tw }))
            hl.dispatch(hl.dsp.focus({ window = tw }))
        else
            hl.dispatch(hl.dsp.window.float({ action = "unset", window = tw }))
        end
    end)
end)