{"_id":"page-lifecycle","_rev":"3-09845f044bdff5ed9d32aa2db84fea51","name":"page-lifecycle","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.0":{"name":"page-lifecycle","version":"0.1.0","description":"A JavaScript library to observe Page Lifecycle API states: https://github.com/WICG/page-lifecycle","license":"Apache-2.0","main":"dist/lifecycle.es5.js","module":"dist/lifecycle.mjs","scripts":{"test":"eslint *.js src/**/*","build":"rollup -c"},"repository":{"type":"git","url":"git+https://github.com/GoogleChromeLabs/page-lifecycle.git"},"bugs":{"url":"https://github.com/GoogleChromeLabs/page-lifecycle/issues"},"homepage":"https://github.com/GoogleChromeLabs/page-lifecycle#readme","keywords":["page","lifecycle","unload","beforeunload","visibilityState","visibilitychange","active","passive","hidden","frozen","discarded","terminated"],"author":{"name":"Philip Walton","email":"philip@philipwalton.com","url":"http://philipwalton.com"},"devDependencies":{"babel-core":"^6.26.3","babel-plugin-external-helpers":"^6.22.0","babel-preset-env":"^1.7.0","eslint":"^4.19.1","eslint-config-google":"^0.9.1","rollup":"^0.60.4","rollup-plugin-babel":"^3.0.4","rollup-plugin-multi-entry":"^2.0.2","rollup-plugin-replace":"^2.0.0","rollup-plugin-terser":"^1.0.1"},"eslintConfig":{"root":true,"env":{"browser":true,"es6":true,"node":true,"mocha":true},"globals":{"assert":false,"sinon":false},"parserOptions":{"ecmaVersion":2018,"sourceType":"module"},"extends":["eslint:recommended","google"]},"gitHead":"daeef77806dd820a107f1c3d69b6832465678b8a","_id":"page-lifecycle@0.1.0","_npmVersion":"6.1.0","_nodeVersion":"10.1.0","_npmUser":{"name":"philipwalton","email":"philip@philipwalton.com"},"dist":{"integrity":"sha512-t0pw0qZFNgVV3QLkuX6Ljj8k1blSP9HsyklS6Qmm0BrgXNYQOSk6jKkuP4YeU+/GiD2n+qCz0LxGRi9WpbvGyQ==","shasum":"c74d1103ff1666cd380c19e0adb86fd06397c6e7","tarball":"https://registry.npmjs.org/page-lifecycle/-/page-lifecycle-0.1.0.tgz","fileCount":26,"unpackedSize":122736,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbM/diCRA9TVsSAnZWagAA9yIP/3GgeDvjTTK87eaaqzJZ\ncYZ4k3emqp5FxAEiPx+iiEMmdv/6AAZnPlngPsFFXERK0onw/uQVLpWlExtA\nwLxE2pwTfsqnuSdstKkb5lE3+sc7t7IiuyPCzlHbJvw8w4+S2f89kh4EF2W2\nL8ay7xnEMmxdvh5kcNaBE0YAfrH7yhkwSe6KXJgF2kOwJ0ZujPJPjDlI7Ckl\nrEKEMZdrgP6Fje6Sws2kmNmGKXMBAjESrbxQBMMF6QAa/Nu/kC5bRGIY+Yqc\npP6FwO4yHdpZ74aztFikH02yRsSYvKUiMB4Ijzr8IWJaCrsFua+qsYRMn+9t\niCWZHaZSC6UaYGNWHGuu8Sqmbw02l/qfgS3PgH7GQA+0pyr5BNeYL6CyjMQs\n40odUY/vwoadcEDkukyqVxfw95djkWiyw126qz58UpSYgdAm+D7so04+4R2D\nXTAO3xBRLOzvDGtqkB+MjlZQZq4pLOfAmexnNNJTqMQc8eOva70MTo+CYDmY\nKuQJ0AXihUiNeX0axGDUvZjy3t6gjIiXqbRVa6X+xGCeykuiVTWXwSEdVky7\nzvSsTN+crSBFjoISqYi+oWFM7wE3rvdyzO84+lQu4N3P0XM5hgsZ50pJ0auL\nqOtz2lssstVElbUhV1n4UqgC89MPNKUQ3/phAow7mO1Mr/A6pKqLGOgPiHuZ\nMyTh\r\n=3be4\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD03jUiKMYbNNskTyjVCf9j9RUYzJH0T3s1AC565RpVKQIgFpYrDnK+9iOhfUS0RH2f77XmmxUmi1bpiKqD2VmrirM="}]},"maintainers":[{"name":"philipwalton","email":"philip@philipwalton.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/page-lifecycle_0.1.0_1530132322917_0.8231759231725109"},"_hasShrinkwrap":false},"0.1.1":{"name":"page-lifecycle","version":"0.1.1","description":"A JavaScript library to observe Page Lifecycle API states: https://github.com/WICG/page-lifecycle","license":"Apache-2.0","main":"dist/lifecycle.es5.js","module":"dist/lifecycle.mjs","scripts":{"test":"eslint *.js src/**/* test/*.mjs","build":"rollup -c"},"repository":{"type":"git","url":"git+https://github.com/GoogleChromeLabs/page-lifecycle.git"},"bugs":{"url":"https://github.com/GoogleChromeLabs/page-lifecycle/issues"},"homepage":"https://github.com/GoogleChromeLabs/page-lifecycle#readme","keywords":["page","lifecycle","unload","beforeunload","visibilityState","visibilitychange","active","passive","hidden","frozen","discarded","terminated"],"author":{"name":"Philip Walton","email":"philip@philipwalton.com","url":"http://philipwalton.com"},"devDependencies":{"babel-core":"^6.26.3","babel-plugin-external-helpers":"^6.22.0","babel-preset-env":"^1.7.0","eslint":"^4.19.1","eslint-config-google":"^0.9.1","rollup":"^0.60.4","rollup-plugin-babel":"^3.0.4","rollup-plugin-multi-entry":"^2.0.2","rollup-plugin-replace":"^2.0.0","rollup-plugin-terser":"^1.0.1"},"eslintConfig":{"root":true,"env":{"browser":true,"es6":true,"node":true,"mocha":true},"globals":{"assert":false,"sinon":false,"safari":false},"parserOptions":{"ecmaVersion":2018,"sourceType":"module"},"extends":["eslint:recommended","google"]},"gitHead":"9114d5ded4ffe2e2bea349d2b00de8342b1e9d11","_id":"page-lifecycle@0.1.1","_npmVersion":"6.3.0","_nodeVersion":"10.7.0","_npmUser":{"name":"philipwalton","email":"philip@philipwalton.com"},"dist":{"integrity":"sha512-U+OFlkMBbsZlFV26l6e49ovZ9uxZDlqauhZotuXuRFTCgXsKnCKkPaGmqqzQtOqm03wJFb83kmN5uEkMBzX5Ng==","shasum":"bd1b851b304c94356612a0909d6f9aabc7f5752e","tarball":"https://registry.npmjs.org/page-lifecycle/-/page-lifecycle-0.1.1.tgz","fileCount":23,"unpackedSize":130830,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbZQiyCRA9TVsSAnZWagAAX7UP+QE9g+gKKtqtibXrW1Wj\n6PQ6Oq/uqDG74xYU9bv8GoW2RUNtBBsluAeyw+t6j/W++W0nWOhy+9we1ERR\nTjryz43axqf59ppg2+VkROkv9RlTgMALuK37tSoOHeWkytMyVyr2Sm07RVKa\nZU8WboyQLhqcUwjU2hJm0iB3Hcok0HC6hPGnAmadyt8He6cfJVVWGfBnzr8E\nwSM0PXtrXxDD3YGVSEe39JndWdTwN8EKpTmbiArEayoop+nlQq95OIabacAI\nPJe/40vH6xHZm1EUT40l4TeufolYHzzA8ETFH6WZ1TE2ri7NdPhINOvi/UbA\neLahidAoReavcDfQIedpgQVtbtYLtj5GB3CgqYy4lzEZNrIAsYA19XAbJo5q\nHk54qFCesl6RwVP/nQwRq1aSZcqm1ZTtkRR6ciGG/ZYSS5CxZP6j2v+qZi6q\noGMAKahYLPTIyrJ0lCeubXbR5MfmuRvZ1YFU2nzXdwuqzmyqvmSzYl20ttb8\nsyGaZ1c8w3+gBXM4N/a/91ABkc/BOeAndlVgxXAvU7o83nfTSriS6afVzY1N\n1Bcx7xAGldSsxV6Ra3Ifr9cFbpQTDziZSGH/eA4OpseaLjEbLMDES/BEvcYE\nSosddGBsIPk8cRy3ulv4ps3xyiqX5qzW81WUv0X/wo0+ZLdruXHhXZhqZxyt\nJk9I\r\n=vdbk\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDdQI7rX5uC9Md2AAttMKu+P0z7Qh6Tl63x1O7pJ0s+9wIgXKfac8ahTUBqXGGWSf2nhQqsWy6RgzaPFnf/8hI8MHY="}]},"maintainers":[{"name":"philipwalton","email":"philip@philipwalton.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/page-lifecycle_0.1.1_1533348017753_0.644495783272216"},"_hasShrinkwrap":false},"0.1.2":{"name":"page-lifecycle","version":"0.1.2","description":"A JavaScript library to observe Page Lifecycle API states: https://github.com/WICG/page-lifecycle","license":"Apache-2.0","main":"dist/lifecycle.es5.js","module":"dist/lifecycle.mjs","scripts":{"test":"eslint *.js src/**/* test/*.mjs","build":"rollup -c"},"repository":{"type":"git","url":"git+https://github.com/GoogleChromeLabs/page-lifecycle.git"},"bugs":{"url":"https://github.com/GoogleChromeLabs/page-lifecycle/issues"},"homepage":"https://github.com/GoogleChromeLabs/page-lifecycle#readme","keywords":["page","lifecycle","unload","beforeunload","visibilityState","visibilitychange","active","passive","hidden","frozen","discarded","terminated"],"author":{"name":"Philip Walton","email":"philip@philipwalton.com","url":"http://philipwalton.com"},"devDependencies":{"babel-core":"^6.26.3","babel-plugin-external-helpers":"^6.22.0","babel-preset-env":"^1.7.0","eslint":"^6.2.2","eslint-config-google":"^0.13.0","rollup":"^1.20.2","rollup-plugin-babel":"^4.3.3","rollup-plugin-multi-entry":"^2.1.0","rollup-plugin-replace":"^2.2.0","rollup-plugin-terser":"^5.1.1"},"eslintConfig":{"root":true,"env":{"browser":true,"es6":true,"node":true,"mocha":true},"globals":{"assert":false,"sinon":false,"safari":false},"parserOptions":{"ecmaVersion":2018,"sourceType":"module"},"extends":["eslint:recommended","google"]},"gitHead":"a32563d198a7e4f5c2338fe6a53a02fd5857992b","_id":"page-lifecycle@0.1.2","_nodeVersion":"10.15.3","_npmVersion":"6.11.2","dist":{"integrity":"sha512-+3uccYgL0CXG0KSXRxZi4uc2E6mqFWV5HqiJJgcnaJCiS0LqiuJ4vB420N21NFuLvuvLB4Jr5drgQ2NXAXF9Iw==","shasum":"f17a083c082bd5ababddd77f1025a4b1c8808012","tarball":"https://registry.npmjs.org/page-lifecycle/-/page-lifecycle-0.1.2.tgz","fileCount":23,"unpackedSize":131020,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdZf0DCRA9TVsSAnZWagAAt8kP/22RnXG7al1HtsBpNJtS\nLkxMwrYHOSuXJi6PwUemz5sevy21wP0plGUvIP+nIu7+ActUPd/+fwZ5mj8+\nMizVvyhjorWq2lYFQZW7MzLHuRmyp1XYzhVsW8MK43qfZsf24X/3HcfsBEDh\nc42QREpHaba8A34ebSwMCZiXDXo9zn6v9W0XyPQ5J5I25GmPu4+0ix4tCmmA\njHw5nTjIjjqtz7PMudTj0j/i+jgiz1jkyOq+J5uy1rtD9S7RmCenxdoH+Cdy\n58Wv7HkYMK8MQNJ9/iQlL5uoWRu0VD3m1qfZADNLz8DZAURgVkz01lXoRpEN\n1AJiHyMNsiIJKcFHJl2ItmBRo3MP7qhuxZEQOpflfyyE8TT+HIdq4F22u7Px\n/gpSM9vDawCUsZWWUG2FMk8nk96Bq//3IY8ju3DuUV0zq/IqvRKkpyz15AVM\nf7LhmTk7hbBlxEaQTLydvokLYgDAeBpfALCMIIkcIP5bsFLQ+K8/aULKbAao\nvS95enGsjv6OKfnEEgE7W7lp21+fs+zuC6YTUJo8CtI0MV0w3uqGWoWI4bUO\nLhfiIjg2HEFOveCrgdFgVCaUmUlXfy2NGuFwcxYrowewaBWV9ahUnx58olez\nx6S/WYJY827xcrmujJaRbYVPfUrIoy/tOKEAin1BDVdhUlv4wuLiRnl00UBJ\nlXbP\r\n=CkUJ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDnHLKbkE1aKCP4jNugJCbMrAZSyXwaWiTHRb5BrJ+nVgIgOrhCVWqORAnyoInkdbGYxqe84IlQZhLYVz5dl7BPxyY="}]},"maintainers":[{"name":"philipwalton","email":"philip@philipwalton.com"}],"_npmUser":{"name":"philipwalton","email":"philip@philipwalton.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/page-lifecycle_0.1.2_1566964995229_0.9832246822301194"},"_hasShrinkwrap":false}},"time":{"created":"2018-06-27T20:45:22.916Z","0.1.0":"2018-06-27T20:45:22.982Z","modified":"2022-05-12T12:05:11.779Z","0.1.1":"2018-08-04T02:00:17.842Z","0.1.2":"2019-08-28T04:03:15.360Z"},"maintainers":[{"name":"philipwalton","email":"philip@philipwalton.com"}],"description":"A JavaScript library to observe Page Lifecycle API states: https://github.com/WICG/page-lifecycle","homepage":"https://github.com/GoogleChromeLabs/page-lifecycle#readme","keywords":["page","lifecycle","unload","beforeunload","visibilityState","visibilitychange","active","passive","hidden","frozen","discarded","terminated"],"repository":{"type":"git","url":"git+https://github.com/GoogleChromeLabs/page-lifecycle.git"},"author":{"name":"Philip Walton","email":"philip@philipwalton.com","url":"http://philipwalton.com"},"bugs":{"url":"https://github.com/GoogleChromeLabs/page-lifecycle/issues"},"license":"Apache-2.0","readme":"# PageLifecycle.js\n\n- [Overview](#overview)\n- [Installation](#installation)\n- [Usage](#usage)\n- [API](#api)\n  - [Properties](#properties)\n  - [Methods](#methods)\n  - [Events](#events)\n- [Browser Support](#browser-support)\n\n\n## Overview\n\nPageLifecycle.js is a tiny JavaScript library (<1K gzipped) that allows developers to easily observe [Page Lifecycle API](https://developers.google.com/web/updates/2018/07/page-lifecycle-api) state changes and implement [Page Lifecycle best practices](https://developers.google.com/web/updates/2018/07/page-lifecycle-api#developer-recommendations-for-each-state) consistently across all browsers.\n\n**▶️ View demo: [page-lifecycle.glitch.me](https://page-lifecycle.glitch.me/) 👀**\n\n## Installation\n\nYou can install this library from npm by running:\n\n```sh\nnpm install --save-dev page-lifecycle\n```\n\n## Usage\n\nReleases of this library include three minified, production-ready versions:\n\n**1. ES5: [`dist/lifecycle.es5.js`](/dist/lifecycle.es5.js)** (UMD) ⭐\n\nUse this version for maximum compatibility with legacy browsers (that can't run ES2015+ code).\n\nAs a UMD bundle, it can be required in CommonJS or AMD environments, or it can be loaded with a script tag as the browser global `lifecycle`.\n\n```html\n<script defer src=\"/path/to/lifecycle.es5.js\"></script>\n<script defer>\nlifecycle.addEventListener('statechange', function(event) {\n  console.log(event.oldState, event.newState);\n});\n</script>\n```\n\n**2. ES2015: [`dist/lifecycle.mjs`](/dist/lifecycle.mjs)** (ESM) 🔥\n\nUse this version if you only support ES module-capable browsers or if you're using `<script type=\"module\">` and the `nomodule` fallback [to conditionally target modern browsers](https://philipwalton.com/articles/deploying-es2015-code-in-production-today/).\n\n```html\n<script type=\"module\">\nimport lifecycle from '/path/to/page-lifecycle.mjs';\n\nlifecycle.addEventListener('statechange', function(event) {\n  console.log(event.oldState, event.newState);\n});\n</script>\n```\n\n\n**3. ES2015 (native): [`dist/lifecycle.native.mjs`](/dist/lifecycle.native.mjs)** (ESM w/o `EventTarget` and `Event` shims) ⚠️\n\nUse this version if you're only targeting browsers that [support extending `EventTarget` and `Event` constructors](https://www.chromestatus.com/features/5721972856061952).\n\n*Note: this version is the smallest but will only work in some browsers. The implementation instructions are the same as the ES2015 version above.*\n\n## API\n\nThe PageLifecycle.js library exports a `lifecycle` object, which is a singleton instance of the [`Lifecycle`](/src/Lifecycle.mjs) class. The `Lifecycle` class has the following properties, methods, and events:\n\n### Properties\n\n<table>\n  <tr valign=\"top\">\n    <th align=\"left\">Name</th>\n    <th align=\"left\">Type</th>\n    <th align=\"left\">Description</th>\n  </tr>\n  <tr valign=\"top\">\n    <td><code>state</code></td>\n    <td><code>string</code></td>\n    <td>\n      Returns the current Page Lifecycle state.\n    </td>\n  </tr>\n  <tr valign=\"top\">\n    <td><code>pageWasDiscarded</code></td>\n    <td><code>boolean</code></td>\n    <td>\n      Returns the value of <code>document.wasDiscarded</code> (or <code>false</code> if not present).\n    </td>\n  </tr>\n</table>\n\n### Methods\n\n<table>\n  <tr valign=\"top\">\n    <th align=\"left\">Name</th>\n    <th align=\"left\">Description</th>\n  </tr>\n  <tr valign=\"top\">\n    <td><code>addEventListener</code></td>\n    <td>\n      <p><strong>Parameters:</strong></p>\n      <ul>\n        <li><em>type</em>: <code>string</code></li>\n        <li><em>listener</em>: <code>function(Event)</code></li>\n      </ul>\n      <p>Adds a callback function to be invoked whenever the passed event type is detected. <em>(Note: at the moment only the \"statechange\" event type is supported.)</em></p>\n    </td>\n  </tr>\n  <tr valign=\"top\">\n    <td><code>removeEventListener</code></td>\n    <td>\n      <p><strong>Parameters:</strong></p>\n      <ul>\n        <li><em>type</em>: <code>string</code></li>\n        <li><em>listener</em>: <code>function(Event)</code></li>\n      </ul>\n      <p>Removes a function from the current list of listeners for the passed event type. <em>(Note: at the moment only the \"statechange\" event type is supported.)</em></p>\n    </td>\n  </tr>\n  <tr valign=\"top\">\n    <td><code>addUnsavedChanges</code></td>\n    <td>\n      <p><strong>Parameters:</strong></p>\n      <ul>\n        <li><em>id</em>: <code>Object|Symbol</code></li>\n      </ul>\n      <p>Adds an item to an internal pending-changes stack. Calling this method adds a generic <code>beforeunload</code> listener to the window (if one isn't already added).</p>\n      <p>The argument passed should be unique to this state, as it can only be removed by passing the same argument to <code>removeUnsavedChanges()</code>.\n      </p>\n    </td>\n  </tr>\n  <tr valign=\"top\">\n    <td><code>removeUnsavedChanges</code></td>\n    <td>\n      <p><strong>Parameters:</strong></p>\n      <ul>\n        <li><em>id</em>: <code>Object|Symbol</code></li>\n      </ul>\n      <p>Removes an item matching the passed argument from an internal pending-changes stack. If the stack is empty, the generic <code>beforeunload</code> listener is removed from the window.</p>\n    </td>\n  </tr>\n</table>\n\n### Events\n\n<table>\n  <tr valign=\"top\">\n    <th align=\"left\">Name</th>\n    <th align=\"left\">Description</th>\n  </tr>\n  <tr valign=\"top\">\n    <td><code>statechange</code></td>\n    <td>\n      <p><strong>Properties:</strong></p>\n      <ul>\n        <li><em>newState</em>: <code>string</code> The current lifecycle state the page just transitioned to.</li>\n        <li><em>oldState</em>: <code>string</code> The previous lifecycle state the page just transitioned from.</li>\n        <li><em>originalEvent</em>: <code>Event</code> the DOM event that triggered the state change.</li>\n      </ul>\n      <p>The <code>statechange</code> event is fired whenever the page's lifecycle state changes.</p>\n    </td>\n  </tr>\n</table>\n\n\n## Browser Support\n\n<table>\n  <tr>\n    <td align=\"center\">\n      <img src=\"https://raw.githubusercontent.com/alrra/browser-logos/39.2.2/src/chrome/chrome_48x48.png\" alt=\"Chrome\"><br>\n      ✔\n    </td>\n    <td align=\"center\">\n      <img src=\"https://raw.githubusercontent.com/alrra/browser-logos/39.2.2/src/firefox/firefox_48x48.png\" alt=\"Firefox\"><br>\n      ✔\n    </td>\n    <td align=\"center\">\n      <img src=\"https://raw.githubusercontent.com/alrra/browser-logos/39.2.2/src/safari/safari_48x48.png\" alt=\"Safari\"><br>\n      ✔\n    </td>\n    <td align=\"center\">\n      <img src=\"https://raw.githubusercontent.com/alrra/browser-logos/39.2.2/src/edge/edge_48x48.png\" alt=\"Edge\"><br>\n      ✔\n    </td>\n    <td align=\"center\">\n      <img src=\"https://raw.githubusercontent.com/alrra/browser-logos/39.2.2/src/archive/internet-explorer_9-11/internet-explorer_9-11_48x48.png\" alt=\"Internet Explorer\"><br>\n      9+\n    </td>\n    <td align=\"center\">\n      <img src=\"https://raw.githubusercontent.com/alrra/browser-logos/39.2.2/src/opera/opera_48x48.png\" alt=\"Opera\"><br>\n      ✔\n    </td>\n  </tr>\n</table>\n\nPageLifecycle.js has been tested and known to work in the above browsers.\n","readmeFilename":"README.md"}