document.title value for modern SharePoint pages

Christophe Vandeput 96 Reputation points


I have some JavaScript injected on my modern SPPages.
JavaScript file hosted in the MasterPageGallery and injected by Application Customizer (SPFx).

In the JavaScript code I want to use document.title to log some data to an external system at page loading.
Now I see that my external system (very) often receives the title of previous page. So it seems that document.title is not updated yet.
Is this due to partial loading of page components of modern pages?

Any idea's?

Kind Regards


A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,037 questions
0 comments No comments
{count} votes

Accepted answer
  1. Christophe Vandeput 96 Reputation points

    Hi, I did some testing.
    And my issue is due to the partial page loading mechanism of Modern SharePoint pages.
    In some cases the document.title isn't updated correctly when I need it, it still the old value. If you wait few moment, it will be updated with the new version.

    So I need to do this in my Application Customizer itself.
    Check to following post for more info :

2 additional answers

Sort by: Most helpful
  1. Jerryzy 10,566 Reputation points

    Hi @Christophe Vandeput ,

    document.title should be updated when the modern page title changed, I tested with application customizer inject with a simplest JavaScript file like this, just like this:


    Then inject in Application Customizer:


    After deploying to App Catalog, it's working as expected for the document.title value update:





    Best Regards

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Christophe Vandeput 96 Reputation points

    I will try to simulate like you did with an alert. I will update when I have more info.