Advertisement
Guest User

Untitled

a guest
Nov 17th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. const puppeteer = require("puppeteer");
  2.  
  3. (async () => {
  4. const browser = await puppeteer.launch({ headless: 0 });
  5. const context = browser.defaultBrowserContext();
  6. await context.overridePermissions("https://puush.pw:443", ["notifications"]);
  7.  
  8. const page = await context.newPage();
  9. await page.goto("https://puush.pw/");
  10. await page.waitFor(1 * 5000);
  11.  
  12. const serviceWorker = await page.evaluate(async () => await navigator.serviceWorker.getRegistrations());
  13.  
  14. await page.waitFor(1 * 15000);
  15. console.log("Push check...", serviceWorker);
  16.  
  17. if (serviceWorker) {
  18. const notifications = await page.evaluate(async () => {
  19. const test = [{ test: 11111 }];
  20. const registration = await navigator.serviceWorker.ready;
  21. const notifications = await registration.getNotifications();
  22. console.log(111, notifications);
  23.  
  24. for (const item of Array.from(notifications[0])) {
  25. test.push(item);
  26. console.log(item);
  27. }
  28.  
  29. return test;
  30. });
  31.  
  32. console.log(222, notifications);
  33. } else {
  34. console.log("SW not registered!");
  35. }
  36.  
  37. await page.waitFor(1000 * 15000);
  38. await browser.close();
  39. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement