Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Pages - General Discussions
Unanswered

Capturing front end JS errors?

(2) ShareShare
ReportReport
Posted on by
With Javascript generally recommended as the solution to most validation/visibility/manipulation in Power Pages, has anyone looked at capturing errors and logging them if they occur on the frontend?
 
Categories:
  • Suggested answer
    ArchitectMadhan Profile Picture
    1,580 on at
    Capturing front end JS errors?
    Capturing and logging frontend JavaScript errors is a great way to monitor and improve the user experience on your Power Pages. Here are some methods to achieve this:
    Using window.onerror
    The window.onerror event handler can be used to catch and log errors globally. Here's a basic example:
    window.onerror = function(message, source, lineno, colno, error) {
        // Log the error details
        console.log(`Error: ${message} at ${source}:${lineno}:${colno}`);    
        // Send error details to the server
        fetch('/logError', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                message: message,
                source: source,
                lineno: lineno,
                colno: colno,
                error: error ? error.stack : null
            })
        });    
        // Prevent default error handling    
    return true;
    };

    Using Error Monitoring Tools

    There are several tools available that can help you capture and log frontend errors more efficiently:
    1. Sentry: Provides detailed error tracking and monitoring, allowing you to trace errors through your stack.
    2. TrackJS: Captures JavaScript errors and groups occurrences of the same error together.
    3. Rollbar: Offers real-time error tracking and grouping of similar errors.

    Explanation

    • window.onerror: This method captures errors globally and logs them to the console. It also sends the error details to a server endpoint for further analysis.
    • Error Monitoring Tools: These tools provide more advanced features like error grouping, real-time monitoring, and detailed stack traces.
    If you find this solution useful, please like it and accept it as answer.

    -ArchitectMadhan

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,631 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,976 Most Valuable Professional

Leaderboard