# \[BUG-975\] Vision: Web Browser: PopUp

**URL:** <https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297>\
**Category:** Ignition\
**Created:** [April 29, 2020, 12:19pm UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297 "2020-04-29T12:19:16Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [April 29, 2020, 12:19pm UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297/1 "2020-04-29T12:19:16Z")

</div>

Hi!

I created a page, where I pasted Web Browser component, so I connected to the page from perspective Module (for example ‘/main’).  
In this ‘/main’ page I have the button and when I press this button the page opens in new tab.

In Vision the new tab opens in popup…

How should I set width and height parameters to this popup? It opens very-very small…

![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/0/0d465d71c5309e9288044aae7708f66570027b1a.png)

Thanx in Advance!

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [April 30, 2020, 10:21am UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297/2 "2020-04-30T10:21:49Z")

</div>

please…

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 4, 2020, 3:30pm UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297/3 "2020-05-04T15:30:37Z")

</div>

[https://jxbrowser.support.teamdev.com/support/solutions/articles/9000013056-handling-pop-ups-swing](https://jxbrowser.support.teamdev.com/support/solutions/articles/9000013056-handling-pop-ups-swing)

You’ll need to translate this Java code to Jython. Also, the underlying implementation is going to change from JxBrowser 6 to JxBrowser 7 in a future Ignition 8 release, which as the article mentions will change how this has to be done.

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [May 5, 2020, 5:09am UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297/4 "2020-05-05T05:09:37Z")

</div>

> [@paul-griffith](#):
>
> Java code to Jython

Thanx for the replay!  
It's the easiest way to do it?? 🥶  
Are there any examples how to translate java to python?

And where to paste this code? 😳

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 5, 2020, 4:17pm UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297/5 "2020-05-05T16:17:23Z")

</div>

If you’re on 7.9.13 or .14, the web browser component has an `initialize` extension function that’s perfect for this.

Translating Java to Jython is actually pretty easy; mostly you just need to drop extra syntax; Python doesn’t type variables or parameters, nor require strict function signatures; although a tradeoff is the increased verbosity of not having anonymous classes. Something like this; untested, but should work:

```python
from javax.swing import JFrame
from java.awt.event import WindowAdapter
from com.teamdev.jxbrowser.chromium.events import DisposeListener
from com.teamdev.jxbrowser.chromium.swing import BrowserView
from com.teamdev.jxbrowser.chromium import PopupContainer, PopupHandler

class MyWindowAdapter(WindowAdapter):
    def windowClosing(self, e):
        browser.dispose();

class MyDisposeListener(DisposeListener):
    def __init__ (self, frame):
        self.frame = frame

    def onDisposed(self, event):
        self.frame.setVisible(False)

def invokedLater():
    BrowserView browserView = BrowserView(browser)
    browserView.setPreferredSize(initialBounds.getSize())
    frame = JFrame("Popup")
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE)
    frame.add(browserView, BorderLayout.CENTER)
    frame.pack()
    frame.setLocation(initialBounds.getLocation())
    frame.setVisible(True)
    frame.addWindowListener(MyWindowAdapter())

    browser.addDisposeListener(MyDisposeListener(frame))

class MyPopupContainer(PopupContainer):
    def insertBrowser(self, browser, initialBounds):
        system.gui.invokeLater(invokedLater)

class MyPopupHandler(PopupHandler):
    def handlePopup(self, params):
        return MyPopupContainer()

browser.setPopupHandler(MyPopupHandler())

```

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [May 5, 2020, 4:59pm UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297/6 "2020-05-05T16:59:56Z")

</div>

I use Ignition v.8.0.11

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 5, 2020, 5:02pm UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297/7 "2020-05-05T17:02:44Z")

</div>

Okay, so you don’t have the `initialize` hook, which makes this slightly harder, but you can still run the same code. In `propertyChange`, put all the code behind an `if event.propertyName == "componentRunning":`, then change the `browser` on the last line to `event.source.browser`.

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [May 5, 2020, 5:07pm UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297/8 "2020-05-05T17:07:45Z")

</div>

> [@paul-griffith](#):
>
> event.source.browser

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/d/d37a45f00c28b669631f586b9869a2318da39b4a.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 5, 2020, 5:09pm UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297/9 "2020-05-05T17:09:10Z")

</div>

Try removing the semi-colon–that’s a left-over from java syntax.

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [May 5, 2020, 5:10pm UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297/10 "2020-05-05T17:10:21Z")

</div>

it didn’t help((

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 5, 2020, 5:11pm UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297/11 "2020-05-05T17:11:16Z")

</div>

Double check that you aren’t mixing tabs and spaces in your indentation.

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [May 5, 2020, 5:13pm UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297/12 "2020-05-05T17:13:39Z")

</div>

THanx!! the problem is in spaces) thanx so much)

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [May 5, 2020, 5:19pm UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297/13 "2020-05-05T17:19:02Z")

</div>

The script is now without errors, but where should I set PopUp’s width and height?

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [May 5, 2020, 5:28pm UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297/14 "2020-05-05T17:28:26Z")

</div>

I think that's handled by the line:

> [@paul-griffith](#):
>
> browserView.setPreferredSize(initialBounds.getSize())

You can try doing the following to set your own size though i'm not 100% positive if that will work:

```auto
import java.awt.Dimension; //<--- add this with your other imports
browserView.setPreferredSize(Dimension(300,400))

```

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [May 5, 2020, 5:41pm UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297/15 "2020-05-05T17:41:05Z")

</div>

the popup doesn’t open when I am lunching the project))

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [May 5, 2020, 5:51pm UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297/16 "2020-05-05T17:51:26Z")

</div>

> Blockquote  
> Traceback (most recent call last):  
> File "event:propertyChange", line 45, in   
> AttributeError: 'NoneType' object has no attribute 'setPopupHandler'

source.browser.setPopupHandler(MyPopupHandler()) also doesn't work...

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [May 5, 2020, 6:23pm UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297/17 "2020-05-05T18:23:02Z")

</div>

can you post your complete code from property change?

I’m guessing the source. shouldn’t be there

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [May 5, 2020, 7:29pm UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297/18 "2020-05-05T19:29:27Z")

</div>

```auto
if event.propertyName == 'componentRunning':
	from javax.swing import JFrame
	from java.awt.event import WindowAdapter
	import java.awt.Dimension
	from com.teamdev.jxbrowser.chromium.events import DisposeListener
	from com.teamdev.jxbrowser.chromium.swing import BrowserView
	from com.teamdev.jxbrowser.chromium import PopupContainer, PopupHandler

	
	class MyWindowAdapter(WindowAdapter):
   		def windowClosing(self, e):
			browser.dispose()

	class MyDisposeListener(DisposeListener):
		def __init__ (self, frame):
			self.frame = frame

		def onDisposed(self, event):
			self.frame.setVisible(False)

	def invokedLater():
		BrowserView.browserView = BrowserView(event.source.browser)
		browserView.setPreferredSize(initialBounds.getSize())
		frame = JFrame("Popup")
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE)
		frame.add(browserView, BorderLayout.CENTER)
		frame.pack()
		frame.setLocation(initialBounds.getLocation())
		frame.setVisible(True)
		#frame.setSize(700,500)
		#frame.setPreferredSize(1365, 768)
		frame.addWindowListener(MyWindowAdapter())

		browser.addDisposeListener(MyDisposeListener(frame))

	class MyPopupContainer(PopupContainer):
		def insertBrowser(self, browser, initialBounds):
			system.gui.invokeLater(invokedLater)

	class MyPopupHandler(PopupHandler):
		def handlePopup(self, params):
			return MyPopupContainer()

	event.source.browser.setPopupHandler(MyPopupHandler())

```

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [May 5, 2020, 8:23pm UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297/19 "2020-05-05T20:23:29Z")

</div>

from what I can tell, to get an instance of the browser you have to call:

```auto
browser = event.source.getBrowser() 

```

so in your case you’d have to add the line above and change the last line to:

```auto
browser.setPopupHandler(MyPopupHandler())

```

Hopefully this helps

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [May 5, 2020, 8:31pm UTC](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297/20 "2020-05-05T20:31:07Z")

</div>

> [@Matthew.gaitan](#):
>
> browser = event.source.getBrowser()

like that?:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/c059b813bafa1d34cb1d60cb906424f9b0508980.png)

doesn't work... oh gosh...

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/b/b93347a7c0644636417c55acb98a3267645ec434.png)

[Next page](https://forum.inductiveautomation.com/t/bug-975-vision-web-browser-popup/34297.md?page=2)
