Custom Floating Menu / View focus not working

Hi @Andreas_Hegenberg , I've been using the Floating Web View and love it. Recently I had to reinstall BTT and not sure what changed but when I used to trigger a WebView (ChatGPT), the cursor/focus used be in the search box (have WebView Config setup), but not anymore. The weird part is when I trigger it for the first time (after BTT restarts) it works, but the next time I open the webview (after 5 seconds) the web view opens but the cursor isn't on the search box. Seems like it does something when the webview isn't but in-memory doesn't when the webview has already loaded in BTT's memory

Ideally, it should work since I have set up the WebView Config with document.querySelector("#prompt-textarea").focus(); which brings the cursor to the search box. It's not just with ChatGPT but with my other webviews (Google, YouTube etc)

I have discussed this with you in the past and it used to work with Floating View for some reason, but not working here.

chatgpt.bttpreset (12.5 KB)

I think I'm able to reproduce this, is it maybe a Sonoma related bug? Did you already upgrade to Sonoma?

I'll try to find a workaround.

So there must have been some change in the macOS webview. It's now necessary to call blur() before focusing again.

Try this:

document.querySelector("#prompt-textarea").blur(); 
document.querySelector("#prompt-textarea").focus(); 

I put the java script into a separate action because I believe the User Script (On Load) is currently only triggered when the webview loads the URL - not when it becomes visible.

// for other users looking to do similar things for different websites, this javascript would focus the first text input or textarea it can find:


let textInputs = document.querySelectorAll('input[type=text]');
if(textInputs.length > 0) {
	textInputs[0].blur();
	textInputs[0].focus();
}
let textAreas = document.querySelectorAll('textarea');
if(textAreas.length > 0) {
	textAreas[0].blur();
	textAreas[0].focus();
}

1 Like

Thank you @Andreas_Hegenberg , the blur() method works for ChatGPT. Sorry to bother you again, but I tried it on other views I have (perplexity.ai) and it doesn't seem to work. For example, I tried to hide certain elements on the webpage (which worked with the old floating view) but they don't work :slightly_frowning_face:

I tried this

document.querySelector("#__next > main > div > div.flex.h-full.min-h-\\[100vh\\] > div.lg\\:pr-sm.lg\\:pb-sm.lg\\:pt-sm.grow > div > div > div > div.relative.h-full.flex.flex-col > div.w-full.grow.flex.items-center.-mt-2xl.md\\:mt-0.border-borderMain\\/60.dark\\:border-borderMainDark\\/80.divide-borderMain\\/60.dark\\:divide-borderMainDark\\/80.ring-borderMain.dark\\:ring-borderMainDark.bg-transparent > div > div > div.md\\:text-center.mb-lg.pb-xs.flex.items-center.justify-center > div").style.visibility='hidden';

this hides the element on the webpage

but not on the Floating Menu/View (element is "Where Knowledge begins" text)

floatingview.bttpreset (12.5 KB)
toggleview.bttpreset (25.3 KB)