Forum Discussion

ssfang's avatar
ssfang
Copper Contributor
Dec 02, 2024

Is there a way around running a custom script before all scripts on any web page

Hi,

Is there a way around running a custom script before all scripts on any web page in SharePoint Online Development?

I know how to create extension component and web parts with SharePoint Framework (SPFx), but I found its scripts is loaded by the framework and is executed too late.

So I want to find a way to load my script for any page, including classic and modern pages, in order to take over the data (what data are allowed to be fetched). Besides, my script doens't depend on SharePoint Online objects, and replace the service worker (progressive web apps - Can I have multiple service workers both intercept the same fetch request? - Stack Overflow).

After referring to Key features of the SharePoint Framework

Important

The SharePoint page HTML DOM is not an API. You should avoid taking any dependencies on the page DOM structure or CSS styles, which are subject to change and potentially break your solutions. SharePoint Framework provides a rich API to customize the SharePoint experience in reliable ways and is the only supported means to interact with the SharePoint page HTML DOM.

I found that it is best to do the client-side control by the public REST interfaces used by PnP JS (a safe API for interacting with SharePoint REST APIs and Microsoft Graph APIs) because I think SPFx is mainly applicable for UI function (beautification) after data reach the client browser.

Thanks!

No RepliesBe the first to reply

Resources