# Title for Webview

**URL:** <https://community.folivora.ai/t/title-for-webview/30417>\
**Category:** Feature Requests\
**Created:** [February 18, 2023, 1:06pm UTC](https://community.folivora.ai/t/title-for-webview/30417 "2023-02-18T13:06:45Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![yw4z](https://community.folivora.ai/user_avatar/community.folivora.ai/yw4z/32/10483_2.png) [@yw4z](https://community.folivora.ai/u/yw4z)\
**Post date:** [February 18, 2023, 1:06pm UTC](https://community.folivora.ai/t/title-for-webview/30417/1 "2023-02-18T13:06:45Z")

</div>

i tried to add title definition to webview html but didnt see an effect

```auto
<head>
  <title>SWM - Fullscreen Overlay</title>
</head>

```

like i mentioned in here before, im trying to identify is floating view active or not

> [@Touch events for WebView](https://community.folivora.ai/t/touch-events-for-webview/30316/5):
>
> thanks, i solved temporarily like this SWM changes variable "SWM-OP" to 1 on launch, changes to 0 on close 3 finger tap \> middle finger action checks that variable for detection is SWM visible with advanced condition but it has a serious bug. 3 finger tap stucks as middle finger if BTT crashes while using SWM (saw many times. but reduced last versions) this will not be problem with your fix

giving support for title helps webview can easly selected on visible window list

floating windows visible as BetterTouchTool - - 2147483631 currently  
i guess it should visible as "BetterTouchTool - SWM - Fullscreen Overlay - 2147483631" with title support  
and i can identify is webview active easily with visible\_window\_list contains "BetterTouchTool - SWM - Fullscreen Overlay" advanced conditions

Thanks

---

<div class="post-metadata">

**Author:** ![frypf](https://community.folivora.ai/letter_avatar_proxy/v4/letter/f/dec6dc/32.png) [@frypf](https://community.folivora.ai/u/frypf)\
**Post date:** [March 6, 2023, 12:24pm UTC](https://community.folivora.ai/t/title-for-webview/30417/2 "2023-03-06T12:24:47Z")

</div>

I was just searching for the same ability. I've discovered through long trial and error that it is _technically_ possible to query for a specific webview window via Applescript with:

```auto
property webviewTitle : "whatever your webview's HTML title is"

tell application "System Events" to tell process "BetterTouchTool"
	set wins to (windows whose title is "" and subrole is not "AXSystemFloatingWindow")
	repeat with win in wins
		set found to (first UI element whose description is webviewTitle) of scroll area 1 of group 1 of win
		if (found is not missing value) then return 1
	end repeat
	return 0
end tell

```

This code runs fine within Script Editor, but unfortunately:

- Attempting to run via a BTT `Run Applescript` action locks up the UI (spinning beachball) unless `Run in background` is selected - in which case it's then useless to use as a condition for other triggers because the result is not awaited.
- Using a `runAppleScript()` call from a webview or `Run Javascript` action it runs ok, but is _slooow_ (at least compared to the speed of checking the `visible_window_list` var), again rendering it of little use as a condition for other actions/functions.

I attempted to get around the lack of a window title initially by a similar strategy to @yw4z (setting/unsetting a BTT var to denote when a specific webview is visible), but ran into issues when that webview is cancelled via any means that fails to call its `BTTWillCloseWindow` - because said variable remains set. In the end, I've just had to check for a title-less window on the same level as I've set within the webview's config. But this is fragile, limits options elsewhere, and requires a lot of refactoring across different triggers and js scripts whenever I decide to change the level.

@Andreas_Hegenberg is there any possibility of adding the webview's HTML title as its window name please? Ideally this would also respond to the title being changed during runtime via js, but even just taking the specified title from the HTML would be a huge step up from having to implement these hokey workarounds 🙏.

---

<div class="post-metadata">

**Author:** ![Andreas\_Hegenberg](https://community.folivora.ai/user_avatar/community.folivora.ai/andreas_hegenberg/32/39221_2.png) [@Andreas\_Hegenberg](https://community.folivora.ai/u/Andreas_Hegenberg)\
**Post date:** [March 6, 2023, 12:55pm UTC](https://community.folivora.ai/t/title-for-webview/30417/3 "2023-03-06T12:55:46Z")

</div>

Floating webviews already have their UUID as title. (You can get it by right-clicking the trigger that opens the webview)

---

<div class="post-metadata">

**Author:** ![frypf](https://community.folivora.ai/letter_avatar_proxy/v4/letter/f/dec6dc/32.png) [@frypf](https://community.folivora.ai/u/frypf)\
**Post date:** [March 6, 2023, 1:07pm UTC](https://community.folivora.ai/t/title-for-webview/30417/4 "2023-03-06T13:07:17Z")

</div>

Unfortunately I can't reproduce this expected behaviour - the title of webview windows within BTT's `visible_window_list` is always just "" 🤔.

The `title` property of the UI element I specified via Applescript correctly shows the contents of the HTML title tag that I've set, but there's currently no way to get this information back as a condition (or even via workaround for the reasons described above).

---

<div class="post-metadata">

**Author:** ![Andreas\_Hegenberg](https://community.folivora.ai/user_avatar/community.folivora.ai/andreas_hegenberg/32/39221_2.png) [@Andreas\_Hegenberg](https://community.folivora.ai/u/Andreas_Hegenberg)\
**Post date:** [March 6, 2023, 1:08pm UTC](https://community.folivora.ai/t/title-for-webview/30417/5 "2023-03-06T13:08:14Z")

</div>

Maybe macOS only returns the window title if the title bar is activated for the window 🤔

It seems to work ok for the webviews I checked:

 ![image](https://community.folivora.ai/uploads/default/original/3X/7/9/79df6f99d26a248c613f7099a7e6705dfaf46263.png)

---

<div class="post-metadata">

**Author:** ![frypf](https://community.folivora.ai/letter_avatar_proxy/v4/letter/f/dec6dc/32.png) [@frypf](https://community.folivora.ai/u/frypf)\
**Post date:** [March 6, 2023, 1:11pm UTC](https://community.folivora.ai/t/title-for-webview/30417/6 "2023-03-06T13:11:37Z")

</div>

Ah I see - my webview has its title bar switched off as I'm trying to create a system(ish) native-looking overlay. Back to the drawing board I suppose 🤦‍♂️😂.

---

<div class="post-metadata">

**Author:** ![yw4z](https://community.folivora.ai/user_avatar/community.folivora.ai/yw4z/32/10483_2.png) [@yw4z](https://community.folivora.ai/u/yw4z)\
**Post date:** [March 6, 2023, 1:12pm UTC](https://community.folivora.ai/t/title-for-webview/30417/7 "2023-03-06T13:12:59Z")

</div>

Visible like this in Visible Windows Inspector without UUID  
BetterTouchTool - - 2147483631

Titlebar has no UUID even if titlebar activated  
 ![Screen Shot 2023-03-06 at 16.00.14](https://community.folivora.ai/uploads/default/original/3X/d/4/d494652bc5e4400c83d18eeaf82ec521c58988c5.jpeg)

Properties with AppleScript

`{{minimum value:missing value, orientation:missing value, position:{923, 509}, class:window, accessibility description:missing value, role description:"system dialog", focused:false, title:"", size:{280, 160}, help:missing value, entire contents:{}, enabled:missing value, maximum value:missing value, role:"AXWindow", value:missing value, subrole:"AXSystemDialog", selected:missing value, name:missing value, description:"system dialog"}}`

Attributes with AppleScript

`{{false, false, "", {application "System Events"}, {972, 562, 1252, 722}, {972, 562}, missing value, missing value, missing value, {{SectionUniqueID:"AXContent", SectionDescription:"Content"}}, missing value, false, {-1, 1441}, missing value, missing value, missing value, false, {group 1 of window 1 of application process "BetterTouchTool" of application "System Events"}, "AXWindow", application process "BetterTouchTool" of application "System Events", missing value, missing value, false, "AXSystemDialog", missing value, "system dialog", {280, 160}, missing value, "_NS:10"}}`

UUID for SWM \> SWMFLOAT-5416-4806-A04E-88E117D32D34

But not visible on list

 ![Screen Shot 2023-03-06 at 16.09.22](https://community.folivora.ai/uploads/default/original/3X/a/c/ac69798026c7d1a525c3a8d680b36494bc03a030.jpeg)

Thanks

---

<div class="post-metadata">

**Author:** ![Andreas\_Hegenberg](https://community.folivora.ai/user_avatar/community.folivora.ai/andreas_hegenberg/32/39221_2.png) [@Andreas\_Hegenberg](https://community.folivora.ai/u/Andreas_Hegenberg)\
**Post date:** [March 6, 2023, 1:13pm UTC](https://community.folivora.ai/t/title-for-webview/30417/8 "2023-03-06T13:13:25Z")

</div>

I'll check again, maybe there is something wrong with the code

I think a more performant way would be to set a variable in the lifecycle methods (BTTInitialize and BTTWillCloseWindow), then you could just query that variable and BTT wouldn't need to reload the window list. Doesn't that worK?

The customVariable1-5 can even be used in conditional activation groups.

---

<div class="post-metadata">

**Author:** ![frypf](https://community.folivora.ai/letter_avatar_proxy/v4/letter/f/dec6dc/32.png) [@frypf](https://community.folivora.ai/u/frypf)\
**Post date:** [March 6, 2023, 1:15pm UTC](https://community.folivora.ai/t/title-for-webview/30417/9 "2023-03-06T13:15:05Z")

</div>

Yes I've just changed my titlebar options and I'm seeing the same results as @yw4z just described. Thanks for looking into this 👍.

---

<div class="post-metadata">

**Author:** ![yw4z](https://community.folivora.ai/user_avatar/community.folivora.ai/yw4z/32/10483_2.png) [@yw4z](https://community.folivora.ai/u/yw4z)\
**Post date:** [March 6, 2023, 1:25pm UTC](https://community.folivora.ai/t/title-for-webview/30417/10 "2023-03-06T13:25:52Z")

</div>

im setting a variable on launch with SWM-ON \> 1  
then settting variable to 0 on close

but it leads to a serious bug. if SWM or BTT crashes variable stucks on 1 until next launch of SWM

Its serious because i use it for middleclick and 3 finger tap detection

BTT starts to ask which trigger to use on use these triggers if user assigned more to them

![Screen Shot 2023-03-06 at 16.17.32](https://community.folivora.ai/uploads/default/original/3X/8/f/8fc3a4c044660a46d5e0b59d1e2b1fb353a223b8.jpeg)

 ![Screen Shot 2023-03-06 at 16.17.19](https://community.folivora.ai/uploads/default/original/3X/7/0/70ed2eecf65796185d87b93b8d314625bc53ab52.jpeg)

---

<div class="post-metadata">

**Author:** ![Andreas\_Hegenberg](https://community.folivora.ai/user_avatar/community.folivora.ai/andreas_hegenberg/32/39221_2.png) [@Andreas\_Hegenberg](https://community.folivora.ai/u/Andreas_Hegenberg)\
**Post date:** [March 6, 2023, 1:30pm UTC](https://community.folivora.ai/t/title-for-webview/30417/11 "2023-03-06T13:30:05Z")

</div>

Did you maybe use set\_persistent\_string\_variable instead of set\_string\_variable? (the latter will be gone if BTT quits, the first one persists)

You could also initialize/reset the variable when BTT is launching:

 ![image](https://community.folivora.ai/uploads/default/original/3X/5/4/54f6c5a4d6d8b6c55d7883ba2c98e92938423f94.jpeg)

---

<div class="post-metadata">

**Author:** ![yw4z](https://community.folivora.ai/user_avatar/community.folivora.ai/yw4z/32/10483_2.png) [@yw4z](https://community.folivora.ai/u/yw4z)\
**Post date:** [March 6, 2023, 1:40pm UTC](https://community.folivora.ai/t/title-for-webview/30417/12 "2023-03-06T13:40:20Z")

</div>

Already using set\_persistent\_string\_variable,  
SWM uses more than 10 callBTT and more than 10 applescript/shellscripts on launch  
i guess this causes to BTT crash, but SWM-OP variable turns 1 before BTT crash  
crash ratio is around %1 or %2. but i see daily because i use SWM more than 100 daily

thanks for your suggestion I will add for next release 👍

---

<div class="post-metadata">

**Author:** ![frypf](https://community.folivora.ai/letter_avatar_proxy/v4/letter/f/dec6dc/32.png) [@frypf](https://community.folivora.ai/u/frypf)\
**Post date:** [March 6, 2023, 1:45pm UTC](https://community.folivora.ai/t/title-for-webview/30417/13 "2023-03-06T13:45:35Z")

</div>

> I think a more performant way would be to set a variable in the lifecycle methods (BTTInitialize and BTTWillCloseWindow)

I did try this but found that there are some circumstances where `BTTWillCloseWindow` doesn't seem to be triggered and my variable remains in the state set within `BTTInitialize` (or `BTTNotification`). I'm trying to update an existing webview's contents according to the value of a variable set within another trigger, listening for changes using `BTTNotification`. Or if I call the same trigger again then it should close the webview. I have the logic worked out to do this reliably but I found that when I call the same trigger and close the webview, `BTTWillCloseWindow` is never called. My `Run Javascript` trigger is as follows:

```auto
(async () => {
  const missioncontrol_active = await callBTT("get_number_variable", { variable_name: "missioncontrol_active" });

  if (missioncontrol_active) {
    runShellScript({ script: `afplay /System/Library/Sounds/Bottle.aiff &` });

  } else {

    // this is my current placeholder condition using window level as described above
    // I've tried to just check against a (non-persistent) variable as you've suggested instead, but it's inconsistent
    const list_visible = !!parseInt(await callBTT("trigger_named", { trigger_name: "webview.detect.dynamicList" }));

    // this is set within BTTInitialise or BTTNotification once the webview contents have been loaded / updated
    const current_config = await callBTT("get_string_variable", { variable_name: "dynamicList.loadedConfig" });

    // this is set within other triggers before calling this trigger
    // it should dynamically refresh the webview contents if it is already onscreen
    // or open the webview and load contents according to the specified value if the webview isn't already visible
    const new_config = await callBTT("get_string_variable", { variable_name: "dynamicList.newConfig" });

    // if dynamicList not on-screen || attempting to load same config
    if (!list_visible || current_config === new_config) {

      // this calls the webview trigger itself, which is set to toggle between displayed / hidden
      // if the webview is already on screen and I attempt to load the same config, BTTWillCloseWebview is never called
      // (my 'dynamicList.loadedConfig' var should also be unset, but remains populated)
      await callBTT("trigger_named", { trigger_name: "webview.toggle.dynamicList" }); // toggle dynamicList webview
    };
  };

  returnToBTT();
})();

```

---

<div class="post-metadata">

**Author:** ![Andreas\_Hegenberg](https://community.folivora.ai/user_avatar/community.folivora.ai/andreas_hegenberg/32/39221_2.png) [@Andreas\_Hegenberg](https://community.folivora.ai/u/Andreas_Hegenberg)\
**Post date:** [March 6, 2023, 1:50pm UTC](https://community.folivora.ai/t/title-for-webview/30417/14 "2023-03-06T13:50:52Z")

</div>

If the webview is still active in background it will call the BTTWillHideWindow function instead, so you also might need to change the variable there.

```auto
function BTTWillHideWindow() {
callBTT('set_string_variable', {variable_name: 'customVariable1', to: "off"});

}

```

@yw4z you should **not** use the persistent one if you don't want to have the same state after a crash.

---

<div class="post-metadata">

**Author:** ![frypf](https://community.folivora.ai/letter_avatar_proxy/v4/letter/f/dec6dc/32.png) [@frypf](https://community.folivora.ai/u/frypf)\
**Post date:** [March 6, 2023, 2:05pm UTC](https://community.folivora.ai/t/title-for-webview/30417/15 "2023-03-06T14:05:01Z")

</div>

> [@Andreas\_Hegenberg](#):
>
> If the webview is still active in background it will call the BTTWillHideWindow function instead

Awesome, this is the bit of info I was missing, I should hopefully be able to get it working without querying the windows at all now - thank you 👏.

---

<div class="post-metadata">

**Author:** ![yw4z](https://community.folivora.ai/user_avatar/community.folivora.ai/yw4z/32/10483_2.png) [@yw4z](https://community.folivora.ai/u/yw4z)\
**Post date:** [March 6, 2023, 2:28pm UTC](https://community.folivora.ai/t/title-for-webview/30417/16 "2023-03-06T14:28:52Z")

</div>

@Andreas_Hegenberg

im using these in html

```auto
BTTInitialize=async()=>{callBTT('set_string_variable',{variable_name:'SWM-OP',to:1})}
BTTWillHideWindow=i=>{callBTT('set_string_variable',{variable_name:'SWM-OP',to:0})}
BTTWillCloseWindow=i=>{callBTT('set_string_variable',{variable_name:'SWM-OP',to:0})}

```

but "Preload immediately after BTT launched" option changes SWM-OP variable changes to 1

anyway to skip this

---

<div class="post-metadata">

**Author:** ![Andreas\_Hegenberg](https://community.folivora.ai/user_avatar/community.folivora.ai/andreas_hegenberg/32/39221_2.png) [@Andreas\_Hegenberg](https://community.folivora.ai/u/Andreas_Hegenberg)\
**Post date:** [March 6, 2023, 2:33pm UTC](https://community.folivora.ai/t/title-for-webview/30417/17 "2023-03-06T14:33:03Z")

</div>

When preloading you should use

```auto
function BTTWindowWillBecomeVisible() {

}

```

instead of BTTInitialize I think.

---

<div class="post-metadata">

**Author:** ![yw4z](https://community.folivora.ai/user_avatar/community.folivora.ai/yw4z/32/10483_2.png) [@yw4z](https://community.folivora.ai/u/yw4z)\
**Post date:** [March 6, 2023, 4:11pm UTC](https://community.folivora.ai/t/title-for-webview/30417/18 "2023-03-06T16:11:55Z")

</div>

looks like fixed, but still using visible window list simpler option it would be great if BTT supports

thanks

---

<div class="post-metadata">

**Author:** ![frypf](https://community.folivora.ai/letter_avatar_proxy/v4/letter/f/dec6dc/32.png) [@frypf](https://community.folivora.ai/u/frypf)\
**Post date:** [March 6, 2023, 4:21pm UTC](https://community.folivora.ai/t/title-for-webview/30417/19 "2023-03-06T16:21:01Z")

</div>

Yep think I've honed my logic to work correctly now in this instance, thanks for pointing me in the right direction.

But still definitely not seeing any UUIDs as window titles in the `visible_window_list`, regardless of the title bar settings for individual webviews - that would def be useful in other situations more generally.

---

<div class="post-metadata">

**Author:** ![Andreas\_Hegenberg](https://community.folivora.ai/user_avatar/community.folivora.ai/andreas_hegenberg/32/39221_2.png) [@Andreas\_Hegenberg](https://community.folivora.ai/u/Andreas_Hegenberg)\
**Post date:** [March 6, 2023, 4:24pm UTC](https://community.folivora.ai/t/title-for-webview/30417/20 "2023-03-06T16:24:31Z")

</div>

Using visible\_window\_list is quite performance hungry though (BTT needs to ask the system for all windows, then extract their titles and then run a search on the whole list). Thus if you can get the variable to work, it will be much more efficient.

[Next page](https://community.folivora.ai/t/title-for-webview/30417.md?page=2)
