# Unable to send focus message from script to running session

**URL:** <https://forum.inductiveautomation.com/t/unable-to-send-focus-message-from-script-to-running-session/40455>\
**Category:** Ignition\
**Created:** [November 9, 2020, 5:56pm UTC](https://forum.inductiveautomation.com/t/unable-to-send-focus-message-from-script-to-running-session/40455 "2020-11-09T17:56:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [November 9, 2020, 5:56pm UTC](https://forum.inductiveautomation.com/t/unable-to-send-focus-message-from-script-to-running-session/40455/1 "2020-11-09T17:56:56Z")

</div>

Does anyone know what could be causing a flood of these messages in our console?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/3/932bce2eb0eed0342be87ae15006eeb97b80c316.png)

---

<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:** [November 9, 2020, 6:51pm UTC](https://forum.inductiveautomation.com/t/unable-to-send-focus-message-from-script-to-running-session/40455/2 "2020-11-09T18:51:24Z")

</div>

You’ve got a property change script somewhere trying to call `self.focus()` - start with that in the Find/Replace tool?

It looks like the error itself might be due to a race, where you’re trying to call focus after the component involved has already been removed on the front-end, likely due to navigation.

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [November 9, 2020, 7:16pm UTC](https://forum.inductiveautomation.com/t/unable-to-send-focus-message-from-script-to-running-session/40455/3 "2020-11-09T19:16:28Z")

</div>

I have a customer property setup on a text field and every 300 ms it calls self.focus(). This is to force the focus back into the TextField if the user touches something else on the screen. Is there something I can put in the code so it will not call self.focus() when the component is no longer on the screen?

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [November 24, 2020, 8:37pm UTC](https://forum.inductiveautomation.com/t/unable-to-send-focus-message-from-script-to-running-session/40455/4 "2020-11-24T20:37:13Z")

</div>

I still have not figure out how to stop this from happening. I can reproduce the error.

I have a customer property on a text box bound to now(100) then I have a change script with the following on the customer property:

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/7/c748202f182eb77741159a44e22b9c0aa0be6d93.png)

```auto
	if self.custom.runTimer:
		if self.custom.counter >= self.custom.trigger:
			self.focus()
			self.custom.counter = 0
		else:
			self.custom.counter += 1

```

when this code is running and I close teh browser window I will see the console get logged with the error. Any suggestion of how I can stop this custom change script from running when the browser window gets closed?

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [December 8, 2020, 5:20pm UTC](https://forum.inductiveautomation.com/t/unable-to-send-focus-message-from-script-to-running-session/40455/5 "2020-12-08T17:20:26Z")

</div>

Is this supposed to fix my issue? I am running 8.0.16 and these release note is from 8.1.1 RC1

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/6/262cb9c3e27cdd95e872d0896647ba22a184de4a.png)

---

<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:** [December 8, 2020, 6:15pm UTC](https://forum.inductiveautomation.com/t/unable-to-send-focus-message-from-script-to-running-session/40455/6 "2020-12-08T18:15:13Z")

</div>

No - because it’s a Vision specific bug. Have you contacted support with your issue above?

@cmallonee may know a workaround to prevent a script from running in the time between ‘browser tab closed’ and ‘backend session terminated’.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [December 8, 2020, 6:30pm UTC](https://forum.inductiveautomation.com/t/unable-to-send-focus-message-from-script-to-running-session/40455/7 "2020-12-08T18:30:38Z")

</div>

You could execute some script in the View Shutdown Event to set a property, and then check against this property to verify the View is still running.

 ![Screen Shot 2020-12-08 at 10.30.01AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/1/017c7e362ee5a9fa837e26004386ab756b1df9ba.png)  
 ![Screen Shot 2020-12-08 at 10.22.34AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/b/ab10dea80fd36f02cb236e646cd0d33583c26e88.png)

Then modify your code to use the new property:

```auto
if self.custom.runTimer and self.view.custom.running:
	if self.custom.counter >= self.custom.trigger:
		self.focus()
		self.custom.counter = 0
	else:
		self.custom.counter += 1

```

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [December 8, 2020, 7:47pm UTC](https://forum.inductiveautomation.com/t/unable-to-send-focus-message-from-script-to-running-session/40455/8 "2020-12-08T19:47:06Z")

</div>

Setting running to False in the view shutdown script does not seem to have an effect. I still get flooded with this when I close the browser window.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/5/f524d6b312084d01c1b2444e9a4d95593bf313c2.png)

Does it maybe matter that this view is embedded?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [December 8, 2020, 8:45pm UTC](https://forum.inductiveautomation.com/t/unable-to-send-focus-message-from-script-to-running-session/40455/9 "2020-12-08T20:45:25Z")

</div>

If you modified your script as suggested then I wouldn’t expect it to reach the `focus()` call. Could you provide a screenshot of the code you’re using? have you tried putting in logging in that area to verify the property is being set as part of the Shutdown Event?
