nucliweb / webperf-snippets

⚡️ 💾 Web Performance Snippets
https://webperf-snippets.nucliweb.net
MIT License
1.34k stars 72 forks source link

fix info script so timing script doesn't fail if undefined #7

Closed jhadev closed 2 years ago

jhadev commented 2 years ago

changed this code to avoid empty arrays without objects with 'name' property

const scripts = {
    firstParty: [{ name: "no data" }],
    thirdParty: [{ name: "no data" }],
  };

  if (first.length) {
    scripts.firstParty = first;
  }

  if (third.length) {
    scripts.thirdParty = third;
  }

return scripts

Tested by running on apple.com which has no third party scripts. Note timing script does not fail.

pic-Google Chrome-Apple-07-152022 2

Previous snippet caused this error on apple.com

pic-Google Chrome-Buy 14-inch MacBook Pro - Apple-07-162022

jhadev commented 2 years ago

Cleaned up .gitignore, only beta and .DS_Store are in there now.