ssborbis / ContextSearch-web-ext

Search engine manager for modern browsers
315 stars 35 forks source link

open search page in a popup window #681

Open hg42 opened 4 months ago

hg42 commented 4 months ago

first I have to say, I am an early user and I still love this extension :+1:

I'm not totally sure if this already exists, and I'm only dumb and cannot find it...

I have several engines that can be seen as tools, where I don't want to open a new tab, but want a kind of popup window.

example: DeepL translation

I have a few extensions e.g. that translate a text or give additional info for a selection and popup a small window without leaving the page. I often wished to be able to do that with any engine of CS. I imagine two ways (ideally having both options):

pros:

I guess I could do this with scripting, but... (insert lot's of reasons)

ssborbis commented 4 months ago

I'll look, but I don't think there's anything baked into the webextensions API to open a new window without all the toolbars. I can probably rig up a window.open() call, but there might be a CORS issue when opening websites. Those extensions you mentioned... did they open to external webpages?

The closest thing this extension can do currently in Firefox is to use the browser's sidebar to show results. It's not a popup per se, but does have the advantage of displaying results alongside the current tab.

I'll test some things and let you know.

hg42 commented 4 months ago

sorry, for answering late... I was offline for some time, at least on github

the LanguageTool looks like this:

image

I guess it communicates with some external site, when I inspect the popup, it is a html page

<!DocTtpe html>
<html>
...
</html>

the extension seems to insert a highlighter before text input fields to mark some words and link to the popup, but I don't see how it does this. I think the popup is like you show the sidebar.

The browsers sidebar doesn't seem ideal, because it also contains all my tabs (maaaannnnyyyy!!) and I would have to switch back to Tree Style Tab, which takes a while.

Will CORS also prevent an iframe?

ssborbis commented 4 months ago

Will CORS also prevent an iframe?

I'm going over the possibilities. If it's using the window.open() method, and CORS isn't an issue, you'd be limited to GET-type engines that have all the query parameters in the URL. This might be doable though. Testing from the console seems to give good results (for google at least) window.open("https://www.google.com/search?q=CORS", "blah", "popup");

ssborbis commented 4 months ago

Early testing looks good. I'll add an option to the list of newTab, backgroundTab, etc for search actions. Eventually, I'll add ways to set popup window size and location, but for now it's a 400x300 window that opens at the cursor. It won't work on pages where scripts cant be injected, and it will only show results for engines with search params in the URL. I'll need some fallback code too, but it does work.

ssborbis commented 4 months ago

changes are in the master branch

hg42 commented 4 months ago

sorry, I was off grid again...

Didn't expect it to be implemented with that speed...but I remember you were always fast... :-)

In my first tests it worked well. Thanks for implementing it, it already adds quality to my flow.

LOL, I first didn't get where to find that option, thinking my repo wasn't pulled correctly etc. Then I realized that it's an option assigned to mouse buttons etc. when opening any engine.

Have to think about it :-) This is nice and consistent, any engine can profit of this option and the usage is always the same. Though, my practical usage would be to assign this option to certain engines, that should always be opened like this. It mainly depends on the engine, if it can be shown in a popup window (and also other options, e.g. if I want to open it in the background).

Not sure, if this is already possible, I didn't follow all the development for a longer time, but I didn't find a way to assign it to an engine. I think a combination of both ways would be an "Engine Default" action configurable for each engine. So, e.g. the left mouse button could be assigned to "Engine Default" and would open like it's configured for each engine. But you still can invoke it with other variations by using other buttons and modifiers. This would also be useful for other engine types. Though this is only an idea...

hg42 commented 4 months ago

according to the window size:

because we can drag the window frame to it's optimum size, it would be most intuitive, to have the size automatically remembered for each engine. No config necessary. For most engines, the size will be changed a few times until it works for most cases.

hg42 commented 4 months ago

I had to disable the Firefox popup blocker globally, otherwise I would need to add exceptions for each site where I want to use a popup. Another thing where browsers don't take extensions into account. It would make more sense to be able to add an exception for a script origin instead of the page url.

ssborbis commented 4 months ago

All good observations. I'll see what I can do about a per-engine setting

Looks like firefox has a way of overriding popup blocking programmatically. https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/browserSettings/allowPopupsForUserEvents

I'll look into that

ssborbis commented 2 months ago

Very basic code is now in the latest release. Other users have reported blocked popup windows, but I don't seen to have any issues, even with the FF default popup blocking on and no exceptions. If I can work around blockers, I'll look to implement more features.

hg42 commented 1 month ago

I just updated the extension and tested.

Up to now, it works nice for me.

The popup is a great improvement for tools like translation or tools of all kind without leaving the page and keeping an eye on the page content.

Thanks for the nice work.

hg42 commented 1 month ago

Using it a bit more, the popup is very small for my purposes, I usually cannot see any engine content but only the logo or menu and some headline. Do I have any possibilities to change the window size?

Thinking about it, it is more dependent on the screen size than on the engine. It's basically about how much you still want to see of the original page and where you have space to drag the popup out of the way. Actually, for me it would be ideal to place the popup outside of the browser window (so configuring/saving the position additionally to the size).

The simplest solution would be to save the popup window size and position globally, when I change it, so the next popup would open at the same position and size. Or it may be a setting ideally as a percentage of the window size (including a negative position percentage).

I think, handling it globally would be more convenient than saving it for each engine, because we won't want to change it for each of the hundred engines. If handling it per engine, engines that had no popup yet, could inherit from the last popup saved to solve the "change hundred engines" problem.

ssborbis commented 1 month ago

The simplest solution would be to save the popup window size and position globally, when I change it, so the next popup would open at the same position and size.

I've been trying some things to do just that. I have some resize listeners and hope to save both the window size and position in the future.

Do I have any possibilities to change the window size?

Right now, you can Advanced Options -> Manual Edit button -> and change these settings.

image

Position does nothing at the moment.

hg42 commented 1 month ago

sorry for answering (very) late... nice, I didn't know that button, yet. Will this survive updates? (do you merge the values? if so, how? detecting changes?)

hg42 commented 1 month ago

Ah, I see it's the same like export and with date/time in the exported file name, it's easy to compare before and after (meld/windiff). Thanks...again

hg42 commented 1 month ago

oh, I was confused by the name of the file that is saved if I press Ctrl-S on the advanced options. It seems to be a part of the exported settings and I have to reformat those, because the whole json is in one line. Could this be changed so that the export is readable like the advanced options?

ssborbis commented 1 month ago

Could this be changed so that the export is readable like the advanced options?

Sure... I can add that option. It will increase the file size though, but that's probably not a major concern.

ssborbis commented 1 month ago

option exportJsonPretty added to the master branch