Skip to content

Commit

Permalink
fixed prevented navigation when logging in (#9), fixed login window (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Plastikmensch committed Jul 26, 2020
1 parent e8292a4 commit ab2c249
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,32 @@ function createWindow () {
})

twitterWin.webContents.on('did-finish-load', () => {
//make navigation and back button invisible
/*NOTE: navigation is still possible
there is no good way of preventing it
and I don't want to use executeJavaScript.
There is also no good way to access the twitter settings
Disabling the back button also disables some other buttons
on a profile page, like sending a DM
Good to know: Twitter creates all elements via JS,
which makes did-navigate-in-page event useless,
even though it gets called, because url doesn't change
*/
//make navigation bar and back button invisible
const css =
`[role="banner"] {display: none !important}
.r-u0dd49 {display: none !important}`
twitterWin.webContents.insertCSS(css.trim())
})
//Disable navigation
twitterWin.webContents.on('will-navigate', (event) =>{
event.preventDefault()
})

twitterWin.on('closed', () => {
twitterWin = undefined
common.log('closed twitterWin', 0)
})
event.newGuest = twitterWin
}
else {
twitterWin.loadURL(url)
Expand All @@ -170,7 +185,7 @@ function createWindow () {
mainWindow.webContents.on('will-navigate', (event, url) => {
event.preventDefault()
//Login button doesn't call this anymore
if (url.search('https://twitter.com/login') === 0) {
if (url.search('https://mobile.twitter.com/login') === 0) {
loginWin = new BrowserWindow({ parent: mainWindow, webPreferences: { enableRemoteModule: false, contextIsolation: true } })
loginWin.removeMenu()

Expand All @@ -182,6 +197,7 @@ function createWindow () {
})
event.newGuest = loginWin
loginWin.webContents.on('will-navigate', (event, url) => {
//NOTE: Having to solve a captcha, loads twitter instead
mainWindow.loadURL(url)
loginWin.close()
})
Expand Down Expand Up @@ -469,6 +485,9 @@ else {
/*NOTE: Moving everything inside this to browser-window-created
could have the advantage of having a window reference
*/
/*NOTE: Not a good idea to prevent will-navigate event here,
breaks login window and other functionality
*/
app.on('web-contents-created', (event, contents) => {
//Prevent webview tags
contents.on('will-attach-webview', (event, webPreferences, params) => {
Expand All @@ -479,14 +498,10 @@ else {
contents.on('console-message', (event, level, message, line, sourceId) => {
common.log(`log event: Level: ${level} message: ${message} line: ${line} source: ${sourceId}`, 1)
})
//prevent any window from navigating, which isn't caused by loadURL
contents.on('will-navigate', (event) => {
event.preventDefault()
common.log('prevented navigation', 0)
})
//Prevent any window from opening new windows
contents.on('new-window', (event) => {
event.preventDefault()
common.log('prevented new window')
})
//Deny all permissions by default
contents.session.setPermissionRequestHandler((webContents, permission, callback) => {
Expand Down

0 comments on commit ab2c249

Please sign in to comment.