tridactyl / tridactyl

A Vim-like interface for Firefox, inspired by Vimperator/Pentadactyl.

Home Page:https://tridactyl.xyz

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use firefox's search API

glacambre opened this issue · comments

The search API has landed: https://bugzil.la/1352598#c109
We should use it to enhance open/tabopen/winopen.

There's now a way to get the default search engine (https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/search/get). We have to think about whether we actually want to use this though because what's great about searchengine and searchurls is that it's easy to create new tridactyl search engines while creating new Firefox search engines is quite an involved process (basically you have to write an OpenSearch xml file and upload it to addons.mozilla.org).

It might be a good idea to set searchengine to null in the default config and have Tridactyl use Firefox's default search engine if searchengine is null.

searchengine auto I think fits better with our other settings.

I would be happy also to import all search engines that are defined by Firefox and use their keywords (if such a thing exists), and allow them to be overridden by Tridactyl.

Related: #333

while creating new Firefox search engines is quite an involved process (basically you have to write an OpenSearch xml file and upload it to addons.mozilla.org).

Or simply right click on an input field and select "add as search engine".

Or simply right click on an input field and select "add as search engine".

This only works if the website provides an opensearch xml file. We have quite a few searchurls that do not have an equivalent opensearch file (MDN, OSM, Github, Youtube, Twitter...). For these Firefox suggests adding them as bookmark keywords but we don't have access to bookmark keywords.

Each search engine returned by search.get() has an alias attached; maybe union this with tridactyl's searchurls so users can use both? Check FF bookmarks for a matching alias first, fall back to searchurls keys if there's no FF bookmark, paste it into the address bar straight if both of those fail. Users would be able to use OpenSearch xmls if they're available without losing the quick-and-easy searchurl setting if no xml is available.

Related: #961

It looks like it might be nearly useless to us - search.search can only be called in special event handlers for e.g, browserAction.

We could use it to find the just the name of the user's default search engine and see if we have a search engine defined with the same name.

search.search can only be called in special event handlers

I do wish they'd stop doing this or 1) count normal dom events in the same way 2) provide a permission to disable this check.

See https://bugzilla.mozilla.org/show_bug.cgi?id=1477248. Maybe we can get that change reverted.

Thanks, @evilpie. Added to #760.

Would this fix tabopen & open search not respecting search keywords set in bookmarks, or should I open a separate issue for that?

Edit: nevermind, found #73 (comment).

See https://bugzilla.mozilla.org/show_bug.cgi?id=1477248. Maybe we can get that change reverted.

I just landed the patch that removes the user input requirement. We are probably going to uplift this change to Beta (Firefox 63).

while creating new Firefox search engines is quite an involved process (basically you have to write an OpenSearch xml file and upload it to addons.mozilla.org)

Uploading to addons.mozilla.org is actually not necessary. You just need to have the OpenSearch xml accessible with HTTP(s). My extensions add-custom-search-engine implements this with file.io.

@evilpie am I reading that bugzilla page correctly? It looks like it is labelled as targeting FF64.

Like I said in my previous comment, this landed in Nightly (64) and I am trying to get approval to patch Beta (63) as well.

Edit: Now in Beta as well. Should be in the next Beta build.

FF63 is out so we should probably implement this.

Blocked by #708 as we need the search permission.

This would be really nice to have. I use bunny at work and it doesn't seem to be supported using the :set searchengine feature

Could you open another issue for that? Anything with URL as interface ought to work currently.

Could you open another issue for that? Anything with URL as interface ought to work currently.

Perhaps I am doing it wrong? I am running the command :set searchengine bunny.

Edit: Got it to work. I had to first run the command :set searchurls.bunny <url>. Maybe we can make that more clear in the documentation for :help searchurls?

Each search engine returned by search.get() has an alias attached; maybe union this with tridactyl's searchurls so users can use both? Check FF bookmarks for a matching alias first, fall back to searchurls keys if there's no FF bookmark, paste it into the address bar straight if both of those fail. Users would be able to use OpenSearch xmls if they're available without losing the quick-and-easy searchurl setting if no xml is available.

I hope that searchurls keeps working, whatever else happens. I'd like to be able to define my search engine keywords as part of my versioned Tridactyl config file for use across multiple machines.

Unblocked with the proviso that we release a 1.14.x with the #708 fix in it first. Happy to help anyone who wants to work on this. Ask for help in this issue or on Riot/IRC.

Hey there sorry but I'm fighting getting Tri to respect my default search engine. Basically it defaults to my region Google, while I have added the custom Google NCR engine via this site https://mycroftproject.com/dlstats.html (it's the second link) and have selected it as my default search engine in FF preferences. How can I make it the default search engine also for Tri?
Thank you!

Using Firefox's default search engine is only possible in the betas for now, are you sure that's what you're using? If yes, try :get searchengine. This should return # searchengine =. If it doesn't, run :unset searchengine. This will reset Tridactyl's searchengine to an empty string and thus let it know it should use Firefox's default search engine.

Ups I think I have the stable currently installed, I got it from AMO, guess I'll go with beta!
Can I just install the beta from the link in home over the stable or I'm going to loose some settings?
Thank you for your time!

You're going to lose your settings, unless you use a tridactylrc.

In order to move your settings from stable to beta, you can do this:

  1. Open the tridactyl newtab page
  2. Open the firefox console with <C-I>
  3. run JSON.stringify(tri.config.get)
  4. Copy the string and save it somewhere
  5. Uninstall tridactyl stable
  6. Install tridactyl beta
  7. Open the newtab page
  8. Open the console with <C-I>
  9. Run let myConfig = JSON.parse($THE_STRING_YOU_COPIED_BEFORE); Object.keys(myConfig).forEach(key => tri.config.set(key, myConfig[key]))

And you should be good to go :)

Perfect! The Beta version indeed fixed the search engine issue.

I did a couple small corrections to your suggested steps:
I replaced steps from 1 to 4 with the following

  1. Run in Tri command line the viewconfig
  2. This should open a new tab with the JSON file with all your configs inside the Firefox convenient builtin JSON viewer. In the viewer press the Save or Copy button and store the JSON config content somewhere

I've also replaced the step 9 with the following:

  1. Run the following command in the console and paste the JSON string text that you saved earlier in the pop box field that will be displayed:

     let myConfig = JSON.parse(prompt('Paste the JSON string in the field below')); Object.keys(myConfig).forEach(key => tri.config.set(key, myConfig[key])); alert('Tridactyl settings saved!')
    

I suggest your instructions to be documented somewhere also, I think this could be useful to many people, thank you for your time!