1. Sign in to Office 365 as a global admin or SharePoint admin.
  2. Select the app launcher icon The icon that looks like a waffle and represents a button click that will reveal multiple application tiles for selection. in the upper-left and choose Admin to open the Office 365 admin center. (If you don't see the Admin tile, you don't have Office 365 administrator permissions in your organization.)
  3. In the left pane, choose Admin centers > SharePoint.
  4. Select settings.
  5. Under Custom Script choose:

    • Allow users to run custom script on personal sites.
    • Allow users to run custom script on self-service created sites.

  6. Custom script section of settings page in SharePoint admin center

Before you allow custom script on sites in your organization, make sure you understand the security implications, read more in this Microsoft article..