How to set Ecosia as default search Engine in Opera

Opera GX is a nice browser but currently it doesnt support setting Ecosia as default search engine (they say it’s for security reasons - which I call total bullshit).

However, you can still use Ecosia as your default search engine in Opera GX by using a little JavaScript trick.

  1. Install the TaperMonkey extension in Opera GX.
  2. Set Yahoo! as your default search engine in Opera GX.
  3. Click on the TaperMonkey icon in the top right corner of the browser.
  4. Click on “Create a new script” and paste the following code:
// ==UserScript==
// @name         Ecosia as Default Search Engine in Opera
// @version      1.0
// @description  Sets Ecosia as default search engine by automatically redirecting you when you search in Yahoo.
// @author       Uli Köhler (techoverflow.net)
// @license      CC0-1.0 Universal
// @match        https://search.yahoo.com/search*
// @namespace    http://tampermonkey.net/
// ==/UserScript==
(function() {
    const queryString = window.location.search;
    const urlParams = new URLSearchParams(queryString);
    console.info(urlParams);
    const search = urlParams.get("p");

    window.location.href = 'https://www.ecosia.org/search?q=' + encodeURIComponent(search);
})();

This will redirect every Yahoo! search to Ecosia. Using DuckDuckgo didnt work for me for unknown reasons probably related to broken Javascript being injected.

Inspired by Hagbard Hednig’s code found here, which didnt work in 2024 version of Opera, and also I wanted cleaner code instead of a pesky one-liner, so I’ve rewritten it entirely. This also makes it easy to modify in the future.