Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

521
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!