# Detect the browser

**URL:** <https://discourse.psychopy.org/t/detect-the-browser/40593>\
**Category:** Online experiments\
**Created:** [June 27, 2024, 12:55pm UTC](https://discourse.psychopy.org/t/detect-the-browser/40593 "2024-06-27T12:55:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xuanyu](https://avatars.discourse-cdn.com/v4/letter/x/ce7236/32.png) [@Xuanyu](https://discourse.psychopy.org/u/Xuanyu)\
**Post date:** [June 27, 2024, 12:55pm UTC](https://discourse.psychopy.org/t/detect-the-browser/40593/1 "2024-06-27T12:55:22Z")

</div>

I’d like to restrict the browser that participants use because my experiment has compatibility problem with Brave and potentially others. I use the code following to trace the browser:  
**psychoJS.experiment.addData(“Browser”, window.navigator.userAgent);**

But after testing, it doesn’t correctly distinguish some browsers like Brave. The returned value is the same as Chrome:  
**Brave: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36**  
**Chrome: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36**

Does anyone any suggestions on how to correctly record the browser participants are using and quit the experiment immediately if certain types of browsers are detected?

Thank you!

Best,  
Xuanyu

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [June 27, 2024, 1:01pm UTC](https://discourse.psychopy.org/t/detect-the-browser/40593/2 "2024-06-27T13:01:35Z")

</div>

Made this topic public on June 27, 2024, 1:01pm UTC



---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [June 27, 2024, 1:07pm UTC](https://discourse.psychopy.org/t/detect-the-browser/40593/3 "2024-06-27T13:07:13Z")

</div>

Since the returned value is identical, could you add a question which addresses the compatibility issue. What doesn’t work on Brave?

---

<div class="post-metadata">

**Author:** ![Xuanyu](https://avatars.discourse-cdn.com/v4/letter/x/ce7236/32.png) [@Xuanyu](https://discourse.psychopy.org/u/Xuanyu)\
**Post date:** [June 27, 2024, 1:31pm UTC](https://discourse.psychopy.org/t/detect-the-browser/40593/4 "2024-06-27T13:31:15Z")

</div>

The position of text is weird and there are some overlapping within different text stimuli.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/3/a/3a797bc47a5e2e063f67c4a79d60a88660134c07.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/c/7/c78a7bffbcee1e2532e26557e3d53c0d8c669c1f.png)

Also the size and location of images are not the optimal:In the **Begin Experiment** phase, I read **screen.width** and **screen.height** to arrange three images in a line, adding spacing between them and the screen edges. But in Brave the images align to the edges with no gap.  
In Brave: (no space between images on the sides and the screen edges)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/4/b/4b71463b4da6b2c61f2be64fa5860743b9f4a1f3.jpeg)  
The normal alignment in Chrome/Firefox: (with space gap on sides)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/a/6/a6619bb1a69d26120aa415231331aa1c41564d3b.jpeg)

Thank you for the further help.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [June 27, 2024, 1:43pm UTC](https://discourse.psychopy.org/t/detect-the-browser/40593/5 "2024-06-27T13:43:14Z")

</div>

> [@Xuanyu](#):
>
> In the **Begin Experiment** phase, I read **screen.width** and **screen.height**

Try reading screen height and width in End Routine of the first routine.

Also, I use win.size[0] and win.size[1] instead of screen.width and screen.height

win.size auto translates to psychoJS.window.size

---

<div class="post-metadata">

**Author:** ![Xuanyu](https://avatars.discourse-cdn.com/v4/letter/x/ce7236/32.png) [@Xuanyu](https://discourse.psychopy.org/u/Xuanyu)\
**Post date:** [June 27, 2024, 1:54pm UTC](https://discourse.psychopy.org/t/detect-the-browser/40593/6 "2024-06-27T13:54:12Z")

</div>

Thanks for the advice!

However when I tried to put the codes on End Routine of the first routine, the images can not be loaded correctly:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/0/2/029953d3ef6cce394aaf991257b8ced040846a70.png)

At first I tried to read the screen size with psychoJS.window.size[0] and psychoJS.window.size[1]; but images would align with the edges of the screen somehow. If I read with screen.width and screen.height the images would align correctly with spaces on both sides.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [June 27, 2024, 2:19pm UTC](https://discourse.psychopy.org/t/detect-the-browser/40593/7 "2024-06-27T14:19:52Z")

</div>

You will need to set sizes each repeat rather than constant for this to work

---

<div class="post-metadata">

**Author:** ![Xuanyu](https://avatars.discourse-cdn.com/v4/letter/x/ce7236/32.png) [@Xuanyu](https://discourse.psychopy.org/u/Xuanyu)\
**Post date:** [June 27, 2024, 2:53pm UTC](https://discourse.psychopy.org/t/detect-the-browser/40593/8 "2024-06-27T14:53:06Z")

</div>

Thanks! I will modify the codes to see how it goes. Just to clarify a bit, what’s the difference between screen.width and psychoJS.window.size[0]?
