Power Apps Host Object – Get Web Browser And O/S Details
The Power Apps host object allows us to get a session ID, the operating system, the user-agent or the tenant ID. It helps us understand the current hardware and environment the app is running in. This is very useful information to have when diagnosing Power Apps errors. In this article I will show you how to use the Power Apps host object.
Table of Contents
• Introduction: The Report A Bug Screen
• Setup The SharePoint List
• Create A New Bug Report Screen
• Determine The BrowserUserAgent
• Check The Operating System
• Get-The-Power-Apps-Session-ID
• Obtain The Tenant ID
• Submit The Bug Report To The SharePoint List
Introduction: The Report A Bug Screen
Users of an app can go to the “Report An App Bug” screen to report an issue to the developer. The bug report includes details about the browser user agent, the operating system, the Power Apps session ID and the tenant ID.
Setup The SharePoint List
Create a new SharePoint list with the following columns:
- BugDescription (multiple lines of text)
- BrowserUserAgent (single line text)
- OS (single line text)
- SessionID (single line text)
- TenantID (single line text)
Create A New Bug Report Screen
Open Power Apps Studio and create a new canvas app from blank. Add rectangle to the top of the screen to make a titlebar. Add a label with the text “Report An App Bug” and also insert a bug icon.
Insert a new label with the words Tell Us What Went Wrong and a text input to capture a description of the bug.
Determine The BrowserUserAgent
The browser user agent contains information about the web browser being used to run the app. We can use this User Agent parsing tool to understand what the text string means.
Add a bold label with the words BrowserUserAgent to the app and another label where the value will be shown.
Use this code in the Text property of the label the determine BrowserUserAgent.
Host.BrowserUserAgent
Check The Operating System
Power Apps can be run on many different operating systems including Windows, iOS, Android, and more. It is valuable to know the operating system because Power Apps can have different behavior on each one. To find which operating system is in use add a bold label with the title OS and then insert another label below it to show the value.
Write this code in the Text property of the label to show the operating system.
Host.OSType
Get The Power Apps Session ID
The Power Apps session ID is useful when reporting errors because it can be passed to Microsoft in a help ticket. Microsoft has the ability to view telemetry and see exactly what went wrong.
Place a bold label with the text Session ID onto the screen and create another label below it to store the value.
Use this code in the Text property of the label to get the Power Apps Session ID.
Host.SessionID
Obtain The Tenant ID
The final piece of information we can grab from the Host object is the tenant id where the app is located. Add a bold label to the screen with the text Tenant ID and create another label below it to store the value.
Write this code in the Text property of the label to display the Session ID value.
Host.TenantID
Submit The Bug Report To The SharePoint List
Once the user has written the bug report the they press a submit button to write the form data to the SharePoint list. Go to the Power Apps Data menu and add the Bug Reports SharePoint list.
Insert a new button at the bottom of the screen with the text “Submit”.
Then use this code in the OnSelect property of the button to submit the bug report. The app will display a success message upon submission or an error message if there is some problem.
If(
IsError(
Patch(
'Bug Reports',
Defaults('Bug Reports'),
{
IssueDescription: txt_IssueDescription,
BrowserUserAgent: lbl_BrowserUserAgentValue,
OperatingSystem: lbl_OSValue,
SessionID: lbl_SessionIDValue,
TenantID: lbl_TenantIDValue
}
)
),
Notify("Error: Bug could not be reported to the app developer"),
Notify("Success: Bug was reported to the app developer")
)
Did You Enjoy This Article? 😺
Subscribe to get new Power Apps articles sent to your inbox each week for FREE
Questions?
If you have any questions or feedback about Power Apps Host Object – Get Web Browser And O/S Details please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion.
Awesome, great tutorial 🙂
Can definitely use this in the app
Great article Matthew! I am already logging unhandled errors in my applications. How does this incorporate with automated unhandled error logging? Do you think there is a place for both?
Another great tutorial. The developer can also use the session id to much more information with Azure App Insights – Analyze system-generated logs using Application Insights – Power Apps | Microsoft Learn
Drew,
Thanks for sharing 🙂
Have you given any thought on how to modify this process to enable it to function as a component? Obviously additional parameters (like the SP site, list, app name, etc) would be required, but this would allow us to roll it out to all of our citizen developers as a standard debug option.
Great Matthew! Really like it. I already automatically log unhandled errors. Could I combine this with the automated logging? What do you think?
Felix,
Yes, you could combine this with automated logging. How are you currently doing automatic logs for tracking errors?
Good day! I work on a GCC platform and I do not have the “Host” option under App. Is there another solution to obtain this information for canvas apps? And is there a solution for model-drive apps?
Marie,
GCC always tends to get things later so my advice is is to hold for now.
Hey Matt, is there a way to check when that session ended? Maybe in Power Automate
Bernard,
This would require Azure App Insights to do. App Insights is not a premium feature and its price is based upon usage. For most internal cases, this is only pennies due to low usage.
Great article! I’ll add the session and tenant ID right away to mine!
Additionally, I found it very useful to have these properties as well:
“Device type: ” & If(And(!IsBlank(Acceleration.X), Acceleration.X<>0), “Mobile”, “Computer”)
“Network: ” & If(Connection.Connected, “connected”, “n/a”) & If(Connection.Metered, ” (WAN)”, ” (LAN)”)
“Browser locale: ” & Language()
Gianluca,
Excellent advice. If I could pin this comment to the top of this section I would 😺 📌
Hi Matthew, sure you can!