Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

527
Visualizações
Open ALL External links in Browser (NWjs)

I was trying to make my own standalone copy of Google Chat using NWjs, but I ran into some problems.

So, when you open a link in the NWjs window, it opens in another NWjs window. However, I would like to open it in the default system browser.

I tried using Tampermonkey, which didn't work, since I figured out how to add extensions to NWjs, and making my own extension didn't work either, so I found out about NWjs's inject_js_end and tried to use that.

But, I keep getting Uncaught TypeError: Failed to set the 'innerHTML' property on 'Element': This document requires 'TrustedHTML' assignment. error.

I assumed this was because CSP was blocking my jQuery code, so I modded CSP-Blocker for chrome but it didn't work.

package.json:

{
    "name": "Chat",
    "main": "index.html",
    "chromium-args": "--enable-logging=stderr --load-extension='./AntiCSP'",
    "inject_js_end": "script.js",
    "window": {
        "title": "Chat",
        "icon": "ico.png",
        "width": 1280,
        "height": 720,
        "resizable": true
    }
}

index.html:

<!DOCTYPE html>
<html>
    <head>
        <title>Loading...</title>
    </head>
    
    <body>
        <script>
window.location.replace("https://chat.google.com")
        </script>
    </body>
</html>

script.js

//jQuery here
console.log("[DEBUG]: Replace links to browser...")

$('a').click(function() {
    nw.Shell.openExternal($(this).prop("href"));
})

How can I force all links in the webpage to open in system browser? I am mostly a Python dev and I haven't found any working solutions yet.

EDIT: As Jaredcheeda pointed out, inject_js_end does only run once. Does anyone have other possible solutions I could use? Maybe Tampermonkey...?

EDIT2: Anyone have any ideas? I still don't have any ideas... 

EDIT3: I was maybe thinking of writing some kind of jQuery to replace all <a> tags with <script> tags that could open it in browser with nw.Shell.openExternal(), then loop it. Problem is, I don't know how to do that.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Correct answer: Use the official API

  • https://developers.google.com/chat/api/guides

Anything other than that will just be very hacky. The inject_js_end only runs once. What happens when two people are IMing and a new message is received containing a link, your function to hijack the click event and open in a default browser would need to be re-ran after every IM. You could try listening to navigation events and preventing them, but anything you do is just gonna be hacky at the end.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda