Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML email view: Some links don't open browser #4017

Open
Simon-Laux opened this issue Jul 8, 2024 · 3 comments
Open

HTML email view: Some links don't open browser #4017

Simon-Laux opened this issue Jul 8, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@Simon-Laux
Copy link
Member

Simon-Laux commented Jul 8, 2024

More specifically, links without a schema, like academy.qt.io/enrollments

Expected: Open link in system browser
Actual: Opening opens a blank page in the html viewer.

Tracking down the problem & Solution ideas

Foundation knowledge

The html email window has two parts: the ui and a sandboxed browser view with disable JS in which the html email is loaded.

Email source is loaded from the email:// scheme that is implemented in

ses.protocol.handle('email', () => {
return new Response(Buffer.from(html_content), {
status: 200,
headers: {
'content-type': 'text/html; charset=utf-8',
'Content-Security-Policy': allow_remote_content ? CSP_ALLOW : CSP_DENY,
},
})
})

The http/s handlers are overwritten by handlers that call the http request method of DC core, if allow_remote_content is activated.

Then there is link handling:

const openLink = (url: string) => {
if (url.startsWith('mailto:') || isInviteLink(url)) {
open_url(url)
mainWindow.window?.show()
} else {
if (url.startsWith('http:') || url.startsWith('https:')) {
shell.openExternal(url)
} else {
dialog
.showMessageBox(window, {
buttons: [tx('no'), tx('menu_copy_link_to_clipboard')],
message: tx('ask_copy_unopenable_link_to_clipboard', url),
})
.then(({ response }) => {
if (response == 1) {
clipboard.writeText(url)
}
})
}
}
}

This openLink function is called in two cases:

  • sandboxedView.webContents.on( 'will-navigate', ... source
  • sandboxedView.webContents.setWindowOpenHandler(details => { ... source

seems this is not enough to catch this case.
I suspect it tries to open it via the email:// scheme, so we might need to check if it is a domain that is tried to be opened instead of index.html.

concerns:

  • we might need to expand the function in the future to load embedded images/media from the email in some edge cases? maybe?
  • it might be too late when we get the call to the link in the email scheme handler, the user might already get a white/blank screen and we can not reject the request?
  • last resort could be to modify the html to fix those <a href= links, to add https-scheme, but not sure we want that, could lead to more edge cases/bugs.

If you want or need dev tools for the email content add this to the code in html_email.ts.

sandboxedView.webContents.openDevTools()
@Simon-Laux Simon-Laux added the bug Something isn't working label Jul 8, 2024
@farooqkz
Copy link
Collaborator

@Simon-Laux Thank you so much for the details :)

@farooqkz
Copy link
Collaborator

Okay after investigating, other than Simon's findings, I can also confirm that it's not http, https, file or email protocols either.

@farooqkz
Copy link
Collaborator

This does not trigger either when clicking on the link: https://www.electronjs.org/docs/latest/api/web-contents#event-will-frame-navigate

@farooqkz farooqkz self-assigned this Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants