$Headers.Referer sometimes missing?

Product: PowerShell Universal
Version: 2.10.0

Continuing my migration to 2.10.0 from 1.5.21. I’m noticing in some instances, more often than not, $Headers.Referer is missing when executing endpoints. I was using this variable property to see know what page actions are being performed from to track actions.

Using the developer tools I can see the referer is being sent in the request headers but doesn’t seem to be available all the time in the $Headers variable.

I went through all the variables that were available in that breakpoint but didn’t see anything that had what I was looking for.

Is there a better way to get the current page that I am on so I can pass that to my function I use to log user actions? This is the payload I build to send to azure log analytics.

$LogPayLoad = [PSCustomObject]@{
    IP = $RemoteIpAddress
    Action = if($Method){$Method} else {$Action}
    ActionDetails = $ActionDetails
    ApiReferer = $Headers.Referer
    Client = $Client
    ClientUser = $ClientUser
    Category = $Category
    SubCategory = $SubCategory
    User = if($Identity){$Identity} else {$User}
    UserAgent = $Headers.'User-Agent'
    HttpConnectionId = $ConnectionId
    SessionID = $Session.Id
    AuthPolicies = $Roles
}

I can reproduce this in certain circumstances as well. Here’s my sample. The results are consistent.

New-UDDashboard -Title 'PowerShell Universal' -Content {
    # works
    Show-UDToast ($Headers.Referer)
    New-UDButton -Text 'Click' -OnClick {
        # doesn't work
        Show-UDToast ($Headers.Referer)
    }
    New-UDDynamic -Content {
        # works
        Show-UDToast ($Headers.Referer)
    }
}

Can you provide any script additional examples? I’ll dig into why the button click isn’t working and it may yield a better understanding of why other circumstances wouldn’t work.

Still going through some testing, but it appears to be the -OnClick for New-UDButton that has the problem.
For UDForms, the -OnSubmit has the referer property, unless you pop up a modal, then have an additional New-UDButton in that script block.
So…

New-UDDashboard -Title ‘PowerShell Universal’ -Content {
# works
Show-UDToast ($Headers.Referer)
New-UDButton -Text ‘Click’ -OnClick {
# doesn’t work
Show-UDToast ($Headers.Referer)
}
New-UDDynamic -Content {
# works
Show-UDToast ($Headers.Referer)
}
New-UDForm -Children {
New-UDTextbox
} -OnSubmit {
#Works
Show-UDToast ($Headers.Referer)
}
New-UDForm -Children {
New-UDTextbox
} -OnSubmit {
Show-UDModal {
New-UDButton -Text ‘Click’ -OnClick {
#Doesn’t work
Show-UDToast ($Headers.Referer)
}
}
}
}

I’ve identified the issue. This will be fixed in 2.10.2.