Skip to content
This repository has been archived by the owner on Jun 4, 2023. It is now read-only.

feat: implement experimental dnt setting #400

Merged
merged 4 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/constants/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ export const DEFAULT_SETTINGS: ISettings = {
downloadsPath: remote
? remote.app.getPath('downloads')
: app
? app.getPath('downloads')
: '',
? app.getPath('downloads')
: '',
doNotTrack: true,
};

export const DEFAULT_SEARCH_ENGINES = [
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ export interface ISettings {
darkContents: boolean;
downloadsDialog: boolean;
downloadsPath: string;
doNotTrack: boolean;
}
8 changes: 8 additions & 0 deletions src/main/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import storage from './services/storage';
import Vibrant = require('node-vibrant');
import { IHistoryItem, IBookmark } from '~/interfaces';
import { WEBUI_BASE_URL } from '~/constants/files';
import { windowsManager } from '.';
import { NEWTAB_URL } from '~/constants/tabs';

export class View extends BrowserView {
Expand Down Expand Up @@ -55,6 +56,13 @@ export class View extends BrowserView {
this.window = window;
this.homeUrl = url;

this.webContents.session.webRequest.onBeforeSendHeaders((details, callback) => {
const { object: settings } = windowsManager.settings;
if (settings.doNotTrack)
details.requestHeaders['DNT'] = '1'
callback({ requestHeaders: details.requestHeaders })
});

ipcMain.handle(`get-error-url-${this.webContents.id}`, async e => {
return this.errorURL;
});
Expand Down
12 changes: 10 additions & 2 deletions src/preloads/view-preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,14 @@ if (window.location.host === 'chrome.google.com') {
injectChromeWebstoreInstallButton();
}

const settings = ipcRenderer.sendSync('get-settings-sync');
if (
window.location.href.startsWith(WEBUI_BASE_URL) ||
window.location.protocol === 'wexond-error:'
) {
(async function() {
(async function () {
const w = await webFrame.executeJavaScript('window');
w.settings = ipcRenderer.sendSync('get-settings-sync');
w.settings = settings;
w.require = (id: string) => {
if (id === 'electron') {
return { ipcRenderer };
Expand All @@ -144,6 +145,13 @@ if (
};
}
})();
} else {
(async function () {
if (settings.doNotTrack) {
const w = await webFrame.executeJavaScript('window');
Object.defineProperty(w.navigator, 'doNotTrack', { value: 1 })
}
})()
}

if (window.location.href.startsWith(WEBUI_BASE_URL)) {
Expand Down
20 changes: 11 additions & 9 deletions src/renderer/views/settings/components/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ const MenuItem = observer(
children: any;
icon?: string;
}) => (
<NavigationDrawer.Item
onClick={() => (store.selectedSection = section)}
selected={store.selectedSection === section}
icon={icon}
>
{children}
</NavigationDrawer.Item>
),
<NavigationDrawer.Item
onClick={() => (store.selectedSection = section)}
selected={store.selectedSection === section}
icon={icon}
>
{children}
</NavigationDrawer.Item>
),
);

export default hot(
Expand Down Expand Up @@ -71,7 +71,9 @@ export default hot(
<MenuItem icon={ICON_DOWNLOAD} section="downloads">
Downloads
</MenuItem>
{/* <MenuItem section="privacy">Privacy</MenuItem> */}
<MenuItem icon={icons.shield} section="privacy">
Privacy
</MenuItem>
{/* <MenuItem section="permissions">Site permissions</MenuItem> */}

{/* <MenuItem section="language">Languages</MenuItem> */}
Expand Down
19 changes: 18 additions & 1 deletion src/renderer/views/settings/components/Privacy/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import * as React from 'react';

import { Header } from '../App/style';
import { Header, Row, Title, Control } from '../App/style';
import { Button } from '~/renderer/components/Button';
import store from '../../store';
import { BLUE_500 } from '~/renderer/constants';
import { observer } from 'mobx-react-lite';
import { onSwitchChange } from '../../utils';
import { Switch } from '~/renderer/components/Switch';

const onClearBrowsingData = () => {
store.dialogContent = 'privacy';
};

const DoNotTrackToggle = observer(() => {
const { doNotTrack } = store.settings;

return (
<Row onClick={onSwitchChange('doNotTrack')}>
<Title>Send a "Do Not Track" request with your browsing traffic</Title>
<Control>
<Switch value={doNotTrack} />
</Control>
</Row>
);
});

export const Privacy = () => {
return (
<>
Expand All @@ -20,6 +36,7 @@ export const Privacy = () => {
>
Clear browsing data
</Button>
<DoNotTrackToggle />
</>
);
};