@curiousvlxd/linkedin-badge-renderer 0.1.14 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curiousvlxd/linkedin-badge-renderer",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "linkedin-badge": "src/cli.mjs"
@@ -1,17 +1,23 @@
1
1
  import { withBrowser, createContext, warmUp, waitFonts } from "../playwright.mjs";
2
- import { buildLinkedinWrapperHtml, extractBadgeFromIframe, buildRenderHtml, measureRoot } from "../linkedin.mjs";
2
+ import {
3
+ buildLinkedinWrapperHtml,
4
+ extractBadgeFromIframe,
5
+ buildRenderHtml,
6
+ measureRoot,
7
+ } from "../linkedin.mjs";
3
8
 
4
9
  export async function renderBadgeArtifacts({ handle, theme, size, locale, orientation, pad }) {
5
10
  return await withBrowser(async (browser) => {
6
- const context = await createContext(browser);
11
+ const context = await createContext(browser, theme);
7
12
  const page = await context.newPage();
8
13
 
9
14
  try {
10
15
  await warmUp(context);
11
16
 
12
- await page.setContent(buildLinkedinWrapperHtml({ handle, theme, size, locale, orientation }), {
13
- waitUntil: "domcontentloaded",
14
- });
17
+ await page.setContent(
18
+ buildLinkedinWrapperHtml({ handle, theme, size, locale, orientation }),
19
+ { waitUntil: "domcontentloaded" }
20
+ );
15
21
 
16
22
  const iframeLocator = page.locator(".LI-profile-badge iframe");
17
23
  await iframeLocator.waitFor({ state: "attached", timeout: 30000 });
@@ -24,7 +30,20 @@ export async function renderBadgeArtifacts({ handle, theme, size, locale, orient
24
30
  if (!frame) throw new Error("LinkedIn badge iframe frame is null");
25
31
 
26
32
  await frame.waitForLoadState("load").catch(() => {});
27
- await frame.waitForTimeout(700);
33
+
34
+ await frame
35
+ .waitForSelector(".profile-badge__content, .profile-badge__name, .profile-badge__cta-btn", {
36
+ timeout: 30000,
37
+ })
38
+ .catch(() => {});
39
+
40
+ await frame
41
+ .waitForFunction(() => {
42
+ const imgs = Array.from(document.images || []);
43
+ if (!imgs.length) return false;
44
+ return imgs.every((i) => i.complete && i.naturalWidth > 0);
45
+ }, { timeout: 30000 })
46
+ .catch(() => {});
28
47
 
29
48
  const { badgeInner, cssHrefs } = await extractBadgeFromIframe(frame);
30
49
  const renderHtml = buildRenderHtml({ badgeInner, cssHrefs, pad });
@@ -9,20 +9,14 @@ export async function withBrowser(fn) {
9
9
  }
10
10
  }
11
11
 
12
- export async function createContext(browser) {
12
+ export async function createContext(browser, theme = "light") {
13
13
  return await browser.newContext({
14
14
  userAgent:
15
15
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",
16
-
17
16
  locale: "en-US",
18
-
19
- viewport: {
20
- width: 1920,
21
- height: 1080,
22
- },
23
-
17
+ viewport: { width: 1920, height: 1080 },
24
18
  deviceScaleFactor: 1.5,
25
- colorScheme: "dark",
19
+ colorScheme: theme === "dark" ? "dark" : "light",
26
20
  reducedMotion: "no-preference",
27
21
  });
28
22
  }