pp.mjs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import Vorpal from "vorpal";
  2. import { chromium } from "playwright";
  3. import os from "os";
  4. import fs from "fs";
  5. import path from "path";
  6. import rawCookies from "./cookies.js";
  7. import { setTimeout } from "timers/promises";
  8. const __dirname = new URL(".", import.meta.url).pathname;
  9. function formatCookies(cookies) {
  10. return cookies.map((i) => {
  11. switch (i.sameSite) {
  12. case "no_restriction":
  13. case "None":
  14. i.sameSite = "None";
  15. break;
  16. case "lax":
  17. case "Lax":
  18. i.sameSite = "Lax";
  19. break;
  20. case "strict":
  21. case "Strict":
  22. i.sameSite = "Strict";
  23. break;
  24. default:
  25. i.sameSite = undefined;
  26. break;
  27. }
  28. return i;
  29. });
  30. }
  31. const userDataDir = fs.mkdtempSync(path.join(os.tmpdir(), "myapp"));
  32. const pathToExtension = path.join(
  33. __dirname,
  34. "fngmhnnpilhplaeedifhccceomclgfbg"
  35. );
  36. // 启动浏览器
  37. let context = await chromium.launchPersistentContext(userDataDir, {
  38. headless: false,
  39. locale: "en-US",
  40. timezoneId: "America/New_York",
  41. // proxy: {
  42. // server: "199.188.92.93:8000",
  43. // username: "proxy",
  44. // password: "rPZHv9U",
  45. // },
  46. args: [
  47. `--disable-extensions-except=${pathToExtension}`,
  48. `--load-extension=${pathToExtension}`,
  49. "--window-position=-1280,0",
  50. ],
  51. userAgent:
  52. "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3105.3 Safari/537.36",
  53. });
  54. context.addCookies(
  55. formatCookies([
  56. {
  57. id: 0,
  58. name: "enforce_policy",
  59. value: "ccpa",
  60. path: "/",
  61. hostOnly: false,
  62. httpOnly: false,
  63. domain: ".paypal.com",
  64. expirationDate: 1711644583,
  65. storeId: "0",
  66. sameSite: "no_restriction",
  67. secure: true,
  68. },
  69. {
  70. id: 1,
  71. name: "id_token",
  72. value: "idtokencbd59a20f80342fa884a1c954aba0e9c",
  73. path: "/",
  74. hostOnly: false,
  75. httpOnly: true,
  76. domain: ".paypal.com",
  77. expirationDate: 1711644583,
  78. storeId: "0",
  79. sameSite: "no_restriction",
  80. secure: true,
  81. },
  82. {
  83. id: 2,
  84. name: "AV894Kt2TSumQQrJwe-8mzmyREO",
  85. value: "S23AAPsIRj_t4bk_JoxBuz7gZvDEi4soSgRMB5ILiBwoPDcUvfZTPO8jPdUkwU-Rpbp6DwrOQ0f-TiOavMID82avmOzxa0iLw",
  86. path: "/",
  87. hostOnly: false,
  88. httpOnly: true,
  89. domain: ".paypal.com",
  90. expirationDate: 1711644583,
  91. storeId: "0",
  92. sameSite: "no_restriction",
  93. secure: true,
  94. },
  95. {
  96. id: 3,
  97. name: "LANG",
  98. value: "en_US%253BUS",
  99. path: "/",
  100. hostOnly: false,
  101. httpOnly: true,
  102. domain: ".paypal.com",
  103. expirationDate: 1711644583,
  104. storeId: "0",
  105. sameSite: "no_restriction",
  106. secure: true,
  107. },
  108. {
  109. id: 4,
  110. name: "tsrce",
  111. value: "unifiedloginnodeweb",
  112. path: "/",
  113. hostOnly: false,
  114. httpOnly: true,
  115. domain: ".paypal.com",
  116. expirationDate: 1711644583,
  117. storeId: "0",
  118. sameSite: "no_restriction",
  119. secure: true,
  120. },
  121. {
  122. id: 5,
  123. name: "HaC80bwXscjqZ7KM6VOxULOB534",
  124. value: "iFfqWZ5pGNHC4gNXjYOPGiwzofBTyMHvUf7y5WJn8xxj4YlkiHnRclEj2MnvF1wtxWLKaHFH3pw3a0mT0ayZOtfNRzqEYZvt2ICIIrbtBxDkFR3XrbQHb0KCXZ0ejAOdKx0r1G",
  125. path: "/",
  126. hostOnly: false,
  127. httpOnly: true,
  128. domain: ".paypal.com",
  129. expirationDate: 1711644583,
  130. storeId: "0",
  131. sameSite: "no_restriction",
  132. secure: true,
  133. },
  134. {
  135. id: 6,
  136. name: "DPz73K5mY4nlBaZpzRkjI3ZzAY3QMmrP",
  137. value: "S23AAPsIRj_t4bk_JoxBuz7gZvDEi4soSgRMB5ILiBwoPDcUvfZTPO8jPdUkwU-Rpbp6DwrOQ0f-TiOavMID82avmOzxa0iLw",
  138. path: "/",
  139. hostOnly: false,
  140. httpOnly: true,
  141. domain: ".paypal.com",
  142. expirationDate: 1711644583,
  143. storeId: "0",
  144. sameSite: "no_restriction",
  145. secure: true,
  146. },
  147. {
  148. id: 7,
  149. name: "x-pp-s",
  150. value: "eyJ0IjoiMTcwOTA1MjU4NDc2NSIsImwiOiIwIiwibSI6IjAifQ",
  151. path: "/",
  152. hostOnly: false,
  153. httpOnly: true,
  154. domain: ".paypal.com",
  155. expirationDate: 1711644583,
  156. storeId: "0",
  157. sameSite: "no_restriction",
  158. secure: true,
  159. },
  160. {
  161. id: 8,
  162. name: "login_email",
  163. value: "shannonlilmomma%40aol.com",
  164. path: "/",
  165. hostOnly: false,
  166. httpOnly: true,
  167. domain: ".paypal.com",
  168. expirationDate: 1711644583,
  169. storeId: "0",
  170. sameSite: "no_restriction",
  171. secure: true,
  172. },
  173. ])
  174. );
  175. const page = await context.newPage();
  176. await page.goto("https://paypal.com/myaccount/summary");
  177. await page.waitForLoadState("networkidle");
  178. const url = await page.url();
  179. console.log(url);
  180. if ((await page.locator('//*[text()="Security Challenge"]').count()) > 0) {
  181. await page.waitForURL("*");
  182. }
  183. if (/signin/.test(url)) {
  184. if ((await page.locator('//button[text()="Get a Code"]').count()) > 0) {
  185. // await page.locator('//*[@id="loginWithPassword" and not(@hidden)]').click();
  186. await page.locator('//*[text()="Try another way"]').first().click();
  187. await page.locator('//*[@id="loginWithPassword"]').first().click();
  188. }
  189. }
  190. if(await page.locator('#password').count() > 0) {
  191. await page.fill('#password', 'password');
  192. await page.locator('#btnLogin').first().click();
  193. }