From d8da43ac297e5df51a9c7276579ac3332adfa801 Mon Sep 17 00:00:00 2001 From: Kevin R Date: Wed, 29 Jan 2025 20:24:38 +0100 Subject: [PATCH] Changed google search rwt detection Fixes: - [#134](https://github.com/ClearURLs/Addon/issues/134) - [#187](https://gitlab.com/ClearURLs/rules/-/issues/187) - [#387](https://github.com/ClearURLs/Addon/issues/387) - [#393](https://github.com/ClearURLs/Addon/issues/393) - [#978](https://gitlab.com/ClearURLs/ClearUrls/-/issues/978) - [#980](https://gitlab.com/ClearURLs/ClearUrls/-/issues/980) - [#1301](https://gitlab.com/ClearURLs/ClearUrls/-/issues/1301) - [#1302](https://gitlab.com/ClearURLs/ClearUrls/-/issues/1302) - [#1305](https://gitlab.com/ClearURLs/ClearUrls/-/issues/1305) . . --- CHANGELOG.md | 23 +++++++++++++++++++++ core_js/google_link_fix.js | 41 +++++++++++++++++++++++++++----------- manifest.json | 14 ++++++++++++- 3 files changed, 65 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc1f2cf..a71d477 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Require Firefox >= 55 - Require Chrome >= 37 + +## [1.27.3] - 2025-XX-XX + +### Changed +- Google Search `window.rwt` detection + +### Fixed +- Google Docs + - [#134](https://github.com/ClearURLs/Addon/issues/134) + - [#187](https://gitlab.com/ClearURLs/rules/-/issues/187) + - [#387](https://github.com/ClearURLs/Addon/issues/387) + - [#393](https://github.com/ClearURLs/Addon/issues/393) + - [#978](https://gitlab.com/ClearURLs/ClearUrls/-/issues/978) + - [#980](https://gitlab.com/ClearURLs/ClearUrls/-/issues/980) + - [#1301](https://gitlab.com/ClearURLs/ClearUrls/-/issues/1301) + - [#1302](https://gitlab.com/ClearURLs/ClearUrls/-/issues/1302) + - [#1305](https://gitlab.com/ClearURLs/ClearUrls/-/issues/1305) + + +### Compatibility note +- Require Firefox >= 55 +- Require Chrome >= 37 + ## [1.27.2] - 2025-01-27 ### Fixed diff --git a/core_js/google_link_fix.js b/core_js/google_link_fix.js index a816d9c..73f3316 100644 --- a/core_js/google_link_fix.js +++ b/core_js/google_link_fix.js @@ -26,19 +26,36 @@ function injectFunction() { let ele = document.createElement('script'); - let s = document.getElementsByTagName('script')[0]; - if (s === undefined) { - return; - } - ele.type = 'text/javascript'; - ele.textContent = "Object.defineProperty(window, 'rwt', {" + - " value: function() { return true; }," + - " writable: false," + - " configurable: false" + - "});"; + ele.textContent = ` + (function() { + "use strict"; + + ${hookRwtProperty.toString()} - s.parentNode.insertBefore(ele, s); + const rwtDescriptor = Object.getOwnPropertyDescriptor(window, 'rwt'); + if (!('rwt' in window) || (rwtDescriptor && rwtDescriptor.configurable)) { + hookRwtProperty(); + } + })(); + `; + + let s = document.getElementsByTagName('script')[0]; + if (s !== undefined) { + s.parentNode.insertBefore(ele, s); + } + } + + function hookRwtProperty() { + try { + Object.defineProperty(window, 'rwt', { + configurable: false, + writable: false, + value: function() { return true; } + }); + } catch (e) { + console.debug('ClearURLs: Failed to hook rwt property', e); + } } /* @@ -65,6 +82,6 @@ } }, true); } - + main(); })(window); diff --git a/manifest.json b/manifest.json index d8b1704..60f7863 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "ClearURLs", - "version": "1.27.2", + "version": "1.27.3", "author": "Kevin Roebert", "description": "__MSG_extension_description__", "homepage_url": "https://docs.clearurls.xyz", @@ -270,6 +270,18 @@ "*://*.google.co.zw/*", "*://*.google.cat/*" ], + "include_globs": [ + "http?://www.google.*/", + "http?://www.google.*/#hl=*", + "http?://www.google.*/search*", + "http?://www.google.*/webhp?hl=*", + "https://encrypted.google.*/", + "https://encrypted.google.*/#hl=*", + "https://encrypted.gogole.*/search*", + "https://encrypted.google.*/webhp?hl=*", + "http?://ipv6.google.com/", + "http?://ipv6.google.com/search*" + ], "js": [ "core_js/google_link_fix.js" ],