[Perspective] Opening New Chrome Window From Button

Hello. I'm trying to open a new Chrome window (not a new tab) from a Perspective view using a script event on a button, but to no avail.

This code works inside the Script Console.

try:
	import subprocess
	chrome_path = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
	url = "https://www.google.com/"
	command = "cmd /C \"" + chrome_path + "\" " + url + " --new-window"
	process = subprocess.Popen(command)
	print("Process: %s" % (process))
except:
	import traceback
	print("Error: %s" % traceback.format_exc())

When I execute it in a Perspective session, the process gets created, but no Chrome window appears.

logger.info("Process: %s" % (process))

outputs this message, similarly to what's happening in my Gateway script.

Process: <subprocess.Popen object at 0x1f2a>

Am I missing out something?

Perspective scripts run on the gateway, not the client.

Thank you for your reply. So can you help me understanding why no Chrome window is appearing?

When a script is run from the script console it executes on the computer where the script console is open. When the script runs behind a perspective button, it runs on the gateway. The subprocess.Popen(command) statement runs on the gateway in the scope of the Ignition user. It may be starting a process but only under very unlikely circumstances would a user ever see a new chrome window open. Here is a similar thread that may be helpful.. Executing an external application from Ignition Perspective View

2 Likes

Pretty clear, thank you. So it seems like this is not the proper way I should try to achieve my task.
Our Scada runs in Kiosk mode and when we want to open the PLC embedded web server (Siemens), a new tab opens, but then there isn't a way to go back to the Scada itself.
I've already tried to embed the web server page in a popup with an iFrame, but it doesn't work 'cause
the HTTP response header X-Frame-Options of the website has value "DENY/SAMEORIGIN", so I can't load it in an iFrame.

Have you got any idea to achieve it? Opening a new Chrome window looked the best way, but it seems that's not feasible.

If anyone does, @pturmel will know the answer.

The simplest solution is to access both your gateway and your PLC's embedded webserver through an reverse proxy (on the gateway machine, perhaps). Then both are "same origin" as far are browsers are concerned, and your IFrame will work. Nginx, Apache, HAProxy are all good choices.

There are other advantages to this approach:

  • You can provide/require HTTPS at the proxy level, allowing the proxied content to remain unencrypted locally yet still secure elsewhere.

  • You can conditionally expose parts of your gateway based on connection origin, like preventing public access to the gateway's admin pages, and/or redirect projects to simpler folder names.

  • You can place the proxy in your plant's DMZ, or otherwise block inbound traffic to your production LAN, yet still display the PLC webserver to authenticated users anywhere.

  • You can easily use Let's Encrypt certificates on a public-facing site, having the certificate challenges diverted and handled at the proxy.

1 Like

Is there a reason why this can't just be done with

system.perspective.navigate(url="https://google.com/", newTab=True)

Hello @cmallonee.
As I've said previously, I don't want to open a new tab, but a new window altogether. Is there a way to achieve that? It doesn't seem like that by the doc.

You could modify the behavior of Chrome to accomplish this. browser - Force Chrome to open new pages in new window, not tab? (when opened from a program) - Super User

Unfortunately the Regedit key gets overwritten each time Chrome updates, so that's not a practical solution. Thank you for your hint.