pp.mjs 6.0 KB

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