From fcc8765fd809ebbd114881083ac5f2ad4a9ba068 Mon Sep 17 00:00:00 2001 From: vantezzen Date: Fri, 24 Apr 2020 16:17:49 +0200 Subject: Update agent agent configuration --- docs/backend_api.md | 25 ++++++++++++++++--------- docs/integration.md | 29 ++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/docs/backend_api.md b/docs/backend_api.md index dfc9f22..512912b 100644 --- a/docs/backend_api.md +++ b/docs/backend_api.md @@ -44,28 +44,35 @@ module.exports = Ferdi => class RocketChat extends Ferdi { ``` ### overrideUserAgent() -Validate if the given URL is a valid service instance. +Override the user agent used inside the service webview. #### Returns -`Boolean` +`String` #### Usage ```js -// Discord integration module.exports = Ferdi => class Discord extends Ferdi { overrideUserAgent() { - const useragent = window.navigator.userAgent; - - // Quick and dirty hackfix - const parts = useragent.split('(KHTML, like Gecko)'); - - return parts.join('(KHTML, like Gecko) discord/0.0.248').replace('Electron', 'Discord').replace('Ferdi', 'Discord'); + // Remove Ferdi's signature from the user agent + return window.navigator.userAgent.replace( + /(Ferdi|Electron)\/\S+ \([^)]+\)/g, + "" + ); } }; +``` +```js +module.exports = Ferdi => class Example extends Ferdi { + overrideUserAgent() { + // Use a completely different user agent + return "Mozilla/2.02Gold (Win95; I)"; + } +}; ``` + ### Events Ferdi recipes can hook into the [electron webview events](https://electron.atom.io/docs/api/webview-tag/#dom-events) to trigger custom functions. diff --git a/docs/integration.md b/docs/integration.md index ef9e2a5..21d1399 100644 --- a/docs/integration.md +++ b/docs/integration.md @@ -100,17 +100,32 @@ module.exports = Ferdi => class RocketChat extends Ferdi { `validateServer` needs to return a [`Promise`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise), otherwise validation will fail. -If you need to override the default user-agent in your service, you can do so like the following snippet of code +By default, Ferdi's user agent looks like this: ``` - overrideUserAgent() { - return window.navigator.userAgent.replace( - /(Ferdi|Electron)\/\S+ \([^)]+\)/g, - "" - ); - } +Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.141 Safari/537.36 Ferdi/5.4.4-beta.3 (Electron 8.1.1) ``` +Some services may not be compatible with Ferdi adding it's signature to the user agent. + +If you encounter such a service, you remove this signature with the following snippet of code + +``` +overrideUserAgent() { + return window.navigator.userAgent.replace( + /(Ferdi|Electron)\/\S+ \([^)]+\)/g, + "" + ); +} +``` + +If you want to change the user agent to a different one, you can simply return the String for the new user agent: + +``` +overrideUserAgent() { + return "Mozilla/2.02Gold (Win95; I)"; +} +``` ### webview.js The webview.js is the actual script that will be loaded into the webview. Here you can do whatever you want to do in order perfectly integrate the service into Ferdi. For convenience, we have provided a very simple set of functions to set unread message badges (`Ferdi.setBadge()`) and inject CSS files (`Ferdi.injectCSS()`). -- cgit v1.2.3-70-g09d2