2022-05-01 23:19:58 -04:00
# Build Commands Catalog
Below you'll find a list of build commands contributed by the Nativefier community. They are here as examples, to help you nativefy "complicated" apps that need a bit of elbow grease to work. We need your help to enrich it, as long as you follow these two guidelines:
1. Only add sites that require something special! No need to document here that `simplesite.com` works with a simple `nativefier simplesite.com` 🙂.
2. Please add commands with the _strict necessary_ to make an app work. For example,
- Yes to mention that `--widevine` or some `--browserwindow-options` are necessary...
- ... but don't add other flags that are pure personal preference (e.g. `--disable-dev-tools` or `--disk-cache-size` ).
---
## General recipes
### Window size and position
2022-05-01 21:17:26 -06:00
2022-05-01 23:19:58 -04:00
This allows the last set window size and position to be remembered and applied
after your app is restarted. Note: PR welcome for a built-in fix for that :) .
2022-05-01 21:17:26 -06:00
```sh
nativefier 'https://open.google.com/'
--inject window.js
```
2022-05-01 23:19:58 -04:00
Note: [Inject ](https://github.com/nativefier/nativefier/blob/master/API.md#inject )
the following javascript as `windows.js` to prevent the window size and position to reset.
2022-05-01 21:17:26 -06:00
```javascript
function storeWindowPos() {
2022-05-01 23:19:58 -04:00
window.localStorage.setItem('windowX', window.screenX);
window.localStorage.setItem('windowY', window.screenY);
2022-05-01 21:17:26 -06:00
}
window.moveTo(window.localStorage.getItem('windowX'), window.localStorage.getItem('windowY'));
setInterval(storeWindowPos, 250);
```
2021-05-12 18:39:52 -04:00
## Google apps
2021-05-03 19:08:32 +02:00
2022-01-09 08:42:32 -05:00
(This example documents Google Sheets, but is applicable to other Google apps,
e.g. Google Calendar)
2021-05-03 19:08:32 +02:00
2021-05-12 18:39:52 -04:00
```sh
nativefier 'https://docs.google.com/spreadsheets' \
2021-05-21 23:41:13 -04:00
--user-agent firefox
2021-05-03 19:08:32 +02:00
```
2022-01-09 08:42:32 -05:00
Note: lying about the User Agent is required, else Google will notice your
"Chrome" isn't a real Chrome, and will:
1. Refuse login
2. Break notifications
2021-05-12 18:39:52 -04:00
## Outlook
```sh
nativefier 'https://outlook.office.com/mail'
--internal-urls '.*?(outlook.live.com|outlook.office365.com).*?'
--file-download-options '{"saveAs": true}'
2022-04-10 13:14:29 -04:00
--browserwindow-options '{"webPreferences": { "webviewTag": true, "nodeIntegration": true, "nodeIntegrationInSubFrames": true } }'
2021-05-12 18:39:52 -04:00
```
2021-05-03 19:08:32 +02:00
2021-05-12 18:39:52 -04:00
Note: `--browserwindow-options` is needed to allow pop-outs when creating/editing an email.
2021-05-03 19:08:32 +02:00
## Udemy
2021-05-12 18:39:52 -04:00
```sh
nativefier 'https://www.udemy.com/'
--internal-urls '.*?udemy.*?'
--file-download-options '{"saveAs": true}'
--widevine
2021-05-03 19:08:32 +02:00
```
2021-05-12 18:39:52 -04:00
Note: most videos will work, but to play some DRMed videos you must pass `--widevine` AND [sign the app ](https://github.com/nativefier/nativefier/issues/1147#issuecomment-828750362 ).
2021-05-13 01:53:47 +02:00
2021-05-13 22:51:08 -04:00
## HBO Max
```sh
nativefier 'https://play.hbomax.com/'
--widevine
--enable-es3-apis
& & python -m castlabs_evs.vmp sign-pkg 'name_of_the_generated_hbo_app'
```
Note: as for Udemy, `--widevine` + [app signing ](https://github.com/nativefier/nativefier/issues/1147#issuecomment-828750362 ) is necessary.
2022-01-06 14:09:15 -05:00
## WhatsApp
```sh
nativefier 'https://web.whatsapp.com/'
--inject whatsapp.js
```
With this `--inject` in `whatsapp.js` (and maybe more, see [#1112 ](https://github.com/nativefier/nativefier/issues/1112 )):
```javascript
if ('serviceWorker' in navigator) {
caches.keys().then(function (cacheNames) {
cacheNames.forEach(function (cacheName) {
caches.delete(cacheName);
});
});
}
```
2021-05-13 01:53:47 +02:00
## Spotify
```sh
nativefier 'https://open.spotify.com/'
--widevine
--inject spotify.js
--inject spotify.css
```
Notes:
2021-06-04 18:53:38 -04:00
- You might have to pass `--user-agent firefox` to circumvent Spotify's detection that your browser isn't a real Chrome. But [maybe not ](https://github.com/nativefier/nativefier/issues/1195#issuecomment-855003776 ).
2021-05-21 18:16:59 -04:00
- [Inject ](https://github.com/nativefier/nativefier/blob/master/API.md#inject ) the following javascript as `spotify.js` to prevent "Unsupported Browser" messages.
2022-01-06 14:09:15 -05:00
2021-05-13 01:53:47 +02:00
```javascript
function dontShowBrowserNoticePage() {
2022-01-06 14:09:15 -05:00
const browserNotice = document.getElementById('browser-support-notice');
console.log({ browserNotice });
if (browserNotice) {
// When Spotify displays the browser notice, it's not just the notice,
// but the entire page is focused on not allowing you to proceed.
// So in this case, we hide the body element (so nothing shows)
// until our JS deletes the service worker and reload (which will actually load the player)
document.getElementsByTagName('body')[0].style.display = 'none';
}
2021-05-13 01:53:47 +02:00
}
function reload() {
2022-01-06 14:09:15 -05:00
window.location.href = window.location.href;
2021-05-13 01:53:47 +02:00
}
function nukeWorkers() {
2022-01-06 14:09:15 -05:00
dontShowBrowserNoticePage();
if ('serviceWorker' in navigator) {
caches.keys().then(function (cacheNames) {
cacheNames.forEach(function (cacheName) {
console.debug('Deleting cache', cacheName);
caches.delete(cacheName);
});
});
navigator.serviceWorker.getRegistrations().then((registrations) => {
registrations.forEach((worker) =>
worker
.unregister()
.then((u) => {
console.debug('Unregistered worker', worker);
reload();
})
.catch((e) =>
console.error('Unable to unregister worker', error, { worker }),
),
);
});
}
2021-05-13 01:53:47 +02:00
}
document.addEventListener('DOMContentLoaded', () => {
2022-01-06 14:09:15 -05:00
nukeWorkers();
2021-05-13 01:53:47 +02:00
});
2022-01-06 14:09:15 -05:00
if (document.readyState === 'interactive') {
nukeWorkers();
2021-05-13 01:53:47 +02:00
}
```
2021-05-21 18:16:59 -04:00
- It is also required to [sign the app ](https://github.com/nativefier/nativefier/blob/master/API.md#widevine ), or many songs will not play.
- To hide all download links (as if you were in the actual app), [inject ](https://github.com/nativefier/nativefier/blob/master/API.md#inject ) the following CSS as `spotify.css` :
2022-01-06 14:09:15 -05:00
2021-05-13 01:53:47 +02:00
```css
2022-01-06 14:09:15 -05:00
a[href='/download'] {
display: none;
}
2021-05-13 01:53:47 +02:00
```