Skip to content

Commit

Permalink
Catch if user agent can't be obtained
Browse files Browse the repository at this point in the history
  • Loading branch information
queengooborg committed Dec 10, 2023
1 parent 6b92ec4 commit e80f1c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ app.locals.browserExtensions = browserExtensions;

// Get user agent
app.use((req: Request, res: Response, next: NextFunction) => {
res.locals.browser = parseUA(req.get("User-Agent"), bcdBrowsers);
const ua = req.get("User-Agent");
res.locals.browser = ua ? parseUA(ua, bcdBrowsers) : null;
next();
});

Expand Down
12 changes: 11 additions & 1 deletion views/browserinfo.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ Snippet to display info about the current browser
See the LICENSE file for copyright details
-->

<p class="browserinfo <% if (!browser.inBcd) { %>error-notice<% } %>"><span class="mdi mdi-web"></span> <% if (browser.browser.name) { %>Detected Browser: <%- browser.browser.name %> <%- browser.version %> <% if (!browser.inBcd) { %>(not in BCD v<%- bcdVersion %>)<% } %><% } else {%>Could not determine browser<% } %></p>
<% if (!browser) { %>
<p class="browserinfo error-notice">
<span class="mdi mdi-web"></span>
Could not determine browser
</p>
<% } else { %>
<p class="browserinfo <% if (!browser.inBcd) { %>error-notice<% } %>">
<span class="mdi mdi-web"></span>
<% if (browser.browser.name) { %>Detected Browser: <%- browser.browser.name %> <%- browser.version %> <% if (!browser.inBcd) { %>(not in BCD v<%- bcdVersion %>)<% } %><% } else {%>Could not determine browser<% } %>
</p>
<% } %>

0 comments on commit e80f1c2

Please sign in to comment.