├── .gitignore ├── README.md └── SUMMARY /.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | .gradle 3 | apktool 4 | app 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [ChromeXt](https://github.com/JingMatrix/ChromeXt) 2 | 3 | [![Build](https://img.shields.io/github/actions/workflow/status/JingMatrix/ChromeXt/android.yml?branch=master&logo=github&label=Build&event=push)](https://github.com/JingMatrix/ChromeXt/actions/workflows/android.yml?query=event%3Apush+is%3Acompleted+branch%3Amaster) [![Download](https://img.shields.io/github/v/release/Xposed-Modules-Repo/org.matrix.chromext?color=orange&logoColor=orange&label=Download&logo=DocuSign)](https://github.com/Xposed-Modules-Repo/org.matrix.chromext/releases/latest) [![Total](https://shields.io/github/downloads/Xposed-Modules-Repo/org.matrix.chromext/total?logo=Bookmeter&label=Counts&logoColor=yellow&color=yellow)](https://github.com/Xposed-Modules-Repo/org.matrix.chromext/releases) 4 | 5 | Add UserScript and DevTools supports to Chromium based and WebView based browsers using Xposed framework. 6 | 7 | *Note*: this repo is only for uploading Xposed Modules releases, the orginal project is [ChromeXt](https://github.com/JingMatrix/ChromeXt). 8 | 9 | ## How does it work? 10 | 11 | We hook the `onUpdateUrl` function in [UserScript.kt](app/src/main/java/org/matrix/chromext/hook/UserScript.kt), 12 | add URL comparison there and evaluate JavaScript using the `javascript:` scheme (or DevTools Protocol when possible). 13 | 14 | Chromium based browsers, 15 | such as [Egde](https://www.microsoft.com/en-us/edge/download), 16 | [Bromite](https://github.com/bromite/bromite), 17 | [Samsung Internet](https://en.wikipedia.org/wiki/Samsung_Internet), 18 | and [Brave](https://github.com/brave/brave-browser), are fully supported. 19 | 20 | Most WebView based browsers are also supported, if not, please report it. 21 | Note for WebView based browsers users: you _only_ need to enable this module for the browser application you wish to use, _not_ for any possible WebView applications, _neither_ for the Android system. 22 | 23 | ## Usage 24 | 25 |

26 | 27 | ChromeXt requires **Xposed framework**. 28 | 29 | For root users, install [LSPosed](https://github.com/LSPosed/LSPosed) first, 30 | pick up the latest built APK from my repo's [GitHub Actions](https://github.com/JingMatrix/ChromeXt/actions) and install it. 31 | 32 | For non-root users, 33 | I modify a bit [LSPatch](https://github.com/JingMatrix/LSPatch) to support `ChromeXt`; here is how to use it: 34 | 1. Download the latest `lspatch-release` from my [GitHub Actions](https://github.com/JingMatrix/LSPatch/actions). 35 | 2. Download the latest `ChromeXt.apk` from my [GitHub Actions](https://github.com/JingMatrix/ChromeXt/actions). 36 | 3. Extract previously downloaded files to get files `lspatch.jar` (with some suffix) and `ChromeXt-signed.apk`. 37 | 4. Patch your APK (taking `arm64_ChromePublic.apk` as example) using the following command: `java -jar lspatch.jar arm64_ChromePublic.apk -d -v -m ChromeXt-signed.apk --force`. If `java` environment is not available, please consider using the provided `manager` APK. 38 | 5. Install the patched APK, which might require you to first uninstall the one on your devices. 39 | 40 | Notes: currently _to download_ files from `GitHub Actions`, one needs to log in GitHub. 41 | 42 | The author uploads releases to [Xposed-Modules-Repo](https://github.com/Xposed-Modules-Repo/org.matrix.chromext/releases) when needed, but not that frequently. 43 | 44 | You can then install UserScripts from popular sources: URLs that ends with `.user.js`. 45 | 46 | ### Supported API 47 | 48 | Currently, ChromeXt supports almost all [Tampermonkey APIs](https://www.tampermonkey.net/documentation.php?locale=en): 49 | 50 | 1. @name (colons not allowed), @namespace, @description and so on 51 | 2. @match (conform to the [Chrome Standard](https://developer.chrome.com/docs/extensions/mv2/match_patterns/), supports [regular expressions](https://developer.android.com/reference/java/util/regex/Pattern)) 52 | 3. @include = @match, @exclude 53 | 4. @run-at: document-start, document-end, document-idle (the default and fallback value) 54 | 5. @grant: GM_addStyle, GM_addElement, GM_xmlhttpRequest, GM_openInTab, GM_registerMenuCommand (shown in the `Resources` panel of eruda), GM_unregisterMenuCommand, GM_download, unsafeWindow (= window) 55 | 6. @grant: GM_setValue, GM_getValue (less powerful than GM.getValue), GM_listValues, GM_addValueChangeListener, GM_removeValueChangeListener, GM_setClipboard, GM_cookie, GM_notification, window.close 56 | 7. @require, @resource (without [Subresource Integrity](https://www.tampermonkey.net/documentation.php#api:Subresource_Integrity)) 57 | 58 | These APIs are implemented differently from the official ones, please refer to the source files 59 | [Local.kt](app/src/main/java/org/matrix/chromext/script/Local.kt) and 60 | [GM.js](app/src/main/assets/GM.js) if you have doubts or questions. 61 | 62 | Moreover, there is the powerful (also dangerous) `GM.ChromeXt` API, which must be declared by `@grant GM.ChromeXt` to _unlock_ its usage. 63 | It is locked by default so that the users are protected from malicious UserScripts exploiting ChromeXt. 64 | This API allows scripts to use the JavaScript method `ChromeXt.dispatch(action, payload)`, which is fundamental to implement other APIs. (Hence, one can find usage examples in [GM.js](app/src/main/assets/GM.js)). 65 | Dispatched `action` and `payload` are handled by [Listener.kt](app/src/main/java/org/matrix/chromext/Listener.kt). 66 | 67 | ### UserScripts manager front end 68 | 69 | To manage scripts installed by `ChromeXt`, here are a simple front end hosted on [github.io](https://jingmatrix.github.io/ChromeXt/) and two mirrors of it (in case that you have connection issues): [onrender.com](https://jianyu-ma.onrender.com/ChromeXt/), [netlify.app](https://jianyu-ma.netlify.app/ChromeXt/). 70 | 71 | ### Edit scripts before installing them 72 | 73 | If you cancel the prompt of installing a new UserScript, then you can edit it directly in Chrome. 74 | Use the `Install UserScript` page menu to install your modified UserScript. 75 | 76 | ### DevTools for developers 77 | 78 | From the three dots page menu, ChromeXt offers you the 79 | 1. `Developer tools` menu for the UserScript manager front end, 80 | 2. `Eruda console` menu for other pages. 81 | 82 | For `Edge` browser, these menus are moved to the page info menu, 83 | which locates at the left corner inside the URL input bar. 84 | 85 | For WebView based browsers and _Samsung Internet_, these menu items are presented in the context menu. 86 | 87 | ## Bonus 88 | 89 | Since WebView based browsers have no unified designs, the following 90 | first four features are not supported for them. 91 | (By the same reason, they are neither supported for _Samsung Internet_.) 92 | 93 | ### Open in Chrome 94 | 95 | The application `ChromeXt` is able to 96 | 1. received shared texts to search them using `Google`, 97 | 2. open JavaScript files to install them as UserScripts. 98 | 99 | The reversed priority order of opening which Chromium based browsers is given in [AndroidManifest.xml](app/src/main/AndroidManifest.xml). 100 | 101 | ### Solution of system gesture conflicts 102 | 103 | By default, the history forward gesture of Chrome is available near the vertical center of screen. 104 | On other areas, only the system gesture is available. 105 | One can disable this behavior through the `Developer options` menu. 106 | (Tap seven times on the Chrome version from the Chrome settings, you will see the `Developer options` menu.) 107 | (In [Vivaldi](https://vivaldi.com/en/android/) browsers, `Developer options` menu is removed by its developers.) 108 | 109 | ### Enable reader mode manually 110 | 111 | ChromeXt adds a book icon in the page menu to enable reader (distiller) mode manually. 112 | 113 | ### Export browser bookmarks 114 | 115 | Bookmarks can be exported in HTML format through the `Developer options` menu. 116 | 117 | ### AD Blocker solution 118 | 119 | For blocking network requests, I recommend to use `AdAway` or any proxy AD Blocker such as `clash`. 120 | 121 | A content cosmetic blocker is embedded into ChromeXt with the help of eruda. 122 | To use it, first open the `Eruda console`. 123 | In the `Elements` panel, one can use the `pointer` icon to select elements on the page. 124 | After clicking the `delete` icon for a selected element, a corresponding filter will be saved to the `Resources` panel, 125 | where one can manage previous added filters. 126 | These filters are saved in the browser even after clearing the site's data. 127 | 128 | Another way to block ADs is using the [Content-Security-Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src) to block some scripts from loading. 129 | 130 | ### User-Agent spoofing 131 | 132 | One can edit the User-Agent from the `Info` panel of `Eruda console`. 133 | A valid User-Agent should contain only ASCII characters. 134 | Currently, ChromeXt only changes the `User-Agent` HTTP header, which 135 | works well but is [deprecated](https://wicg.github.io/ua-client-hints/#user-agent). 136 | 137 | For Chromium based browsers, when the User-Agent spoofing is not taking effects, refresh the page using the reload button in the page menu. 138 | (By contrast, a swipe refresh might be insufficient.) 139 | 140 | Note that the DevTools can also change User-Agent. 141 | 142 | ## Contribute to this project 143 | 144 | Before you submit your pull-requests, please ensure that the command 145 | `./gradlew build` or `gradlew.bat build` produces no warnings and no errors. 146 | 147 | Here are corresponding files you might want / need to change: 148 | 1. Front end: [manager.vue](https://github.com/JingMatrix/jingmatrix.github.io/tree/main/components/ChromeXt/manager.vue) 149 | 2. Tampermonkey API: [Local.kt](app/src/main/java/org/matrix/chromext/script/Local.kt) 150 | and [GM.js](app/src/main/assets/GM.js) 151 | 3. Eruda configuration: [eruda.js](app/src/main/assets/eruda.js) 152 | 4. Support more WebView based browsers: [WebView.kt](app/src/main/java/org/matrix/chromext/hook/WebView.kt) 153 | 154 | ## Development plans 155 | 156 | - [x] Make it possible to pass intents to Chrome with `file` scheme 157 | - [x] Fix encoding problem for Chrome downloaded JavaScript files 158 | - [x] Inject module resource into Chrome 159 | - [x] Implement developer tools 160 | - [x] Use local versions of [eruda](https://github.com/liriliri/eruda) 161 | - [x] Improve eruda incorporation with Chrome 162 | - [x] Add more information in the preference screen 163 | - [x] Support more [Tampermonkey API](https://www.tampermonkey.net/documentation.php)s 164 | - [x] Find elegant way to support DevTools for Android 11- 165 | - [x] Add cosmetic AdBlocker using eruda 166 | - [x] Find way to get current interactive tab 167 | - [x] Remove AndroidX Room dependency to reduce app size 168 | - [x] Support non-split version of Android Chrome 169 | - [x] Solve the menu hook problem for non-split versions 170 | - [x] Handle multiple Tab Model 171 | - [x] Forward DevTools server socket 172 | - [x] A mobile friendly DevTools front end 173 | - [x] Allow user to trigger reader mode 174 | - [x] Support @resource API 175 | - [x] Make GestureNav Fix optional 176 | - [x] Add an open source License 177 | - [x] Support mocking User-Agent 178 | - [ ] ~~Support [urlFilter](https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#type-RuleCondition) syntax~~ 179 | - [x] Improve `Open in Chrome` function 180 | - [x] Implement fully `GM_info` 181 | - [x] Eruda fails due to [Injection Sinks](https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API) 182 | - [x] Hide page_info panel automatically 183 | - [x] Fix page menu injection position 184 | - [ ] ~~Use [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/) as UserScript engine~~ 185 | - [ ] ~~Use `adb forward` to support non-root users~~ 186 | - [x] Fully support WebView based browsers 187 | - [x] Fix [LSPatch for isolated process](https://github.com/LSPosed/LSPatch/issues/190) issue 188 | - [x] Implement UserScript storage 189 | - [x] Re-implement GM_xmlhttpRequest 190 | - [x] Convert exported bookmarks to HTML format 191 | - [x] Show executed scripts on current page 192 | - [x] Make a YouTube presentation video 193 | - [x] Support Samsung Internet browser 194 | - [x] Implement GM_cookie 195 | - [x] Improve valid UserScripts Url detection 196 | - [ ] Save and present script errors and `GM_log` logs 197 | - [ ] Use `iframe` and local server to run general [WebExtensions](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions) 198 | - [ ] Bypass `style-src` rule for `eruda`, such as Mastodon 199 | - [ ] Support importing UserScripts from Tampermonkey exports 200 | - [ ] Support backup and restore 201 | - [ ] Add recommended UserScripts to the front end manager 202 | - [x] Add [chrome devtools front-end](https://chromium.googlesource.com/devtools/devtools-frontend/) for Edge, see [devtools_http_handler.cc](https://source.chromium.org/chromium/chromium/src/+/main:content/browser/devtools/devtools_http_handler.cc) as reference. 203 | - [x] Hide inserted menu for non-page 204 | -------------------------------------------------------------------------------- /SUMMARY: -------------------------------------------------------------------------------- 1 | Add UserScript and DevTools supports to Chromium based and WebView based browsers using Xposed framework. 2 | 3 | For example, Android Chrome, Edge, Vivaldi, Samsung Internet, Bromite, and FOSS browsers are supported. 4 | See README for some other bonus features. 5 | --------------------------------------------------------------------------------