Hi @kekkou,
Hope all is well.
After a further search and testing, there is no way for us to run our custom scripts before all the scripts on the SharePoint page.
SharePoint REST API or Microsoft Graph API are used to manage resources in SharePoint Online, such as lists or document libraries. Before we can use these APIs, we have to make the script file a resource by saving it to our site. So before running custom scripts, we had to run SharePoint related scripts to initialize the site and get the script file.
Using the Rest API to run a custom script as an example, we need to specify where to save the script file.
In addition, to protect your property, SharePoint does not provide us with a proper interface to run custom scripts before we run all SharePoint scripts. This can easily lead to script injection hazards.
SharePoint cannot recognize what scripts are inserted, where they are inserted and who inserted them. If a dangerous or malicious script is inserted, the only way you can stop it is to delete the page hosting it. This can lead to data loss.
Since PnP JS is beyond the scope of our support, we don't have any more relevant resources to determine if PnP JS will solve your problem. Currently, it would be advisable to post a new question in this PnP JS community.
Note: Non-official, just for reference.
Please kindly notice that I am always on standby to support you. Please feel free to let me know if you have any concerns.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. It will be beneficial to more community members reading here.