{"record":{"id":"e657e560bf317954","repo":"jackwener/OpenCLI","slug":"linkedin-company-extraction-returned-a-malformed-c","errorCode":null,"errorMessage":"LinkedIn company extraction returned a malformed current URL","messagePattern":"LinkedIn company extraction returned a malformed current URL","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/linkedin/company.js","lineNumber":83,"sourceCode":"      industry: facts['industry'] || '',\n      size: facts['company size'] || '',\n      headquarters: facts['headquarters'] || '',\n      founded: facts['founded'] || '',\n      website: facts['website'] || '',\n      specialties: facts['specialties'] || '',\n      followers: followersMatch ? followersMatch[1].replace(/,/g, '') : '',\n      about: about.slice(0, 2000),\n    };\n  })()`;\n}\n\nfunction normalizeCompanyOutputUrl(value, fallbackUrl) {\n    const raw = normalizeWhitespace(value || fallbackUrl);\n    let parsed;\n    try {\n        parsed = new URL(raw, `https://${LINKEDIN_DOMAIN}`);\n    } catch {\n        throw new CommandExecutionError('LinkedIn company extraction returned a malformed current URL');\n    }\n    if (parsed.protocol !== 'https:' || parsed.username || parsed.password || parsed.port || !LINKEDIN_COMPANY_HOSTS.has(parsed.hostname.toLowerCase())) {\n        throw new CommandExecutionError('LinkedIn company extraction ended on a non-LinkedIn page');\n    }\n    const match = parsed.pathname.match(COMPANY_URL_RE);\n    if (!match?.[1]) {\n        throw new CommandExecutionError('LinkedIn company extraction ended outside a company page');\n    }\n    let slug;\n    try {\n        slug = decodeURIComponent(match[1]);\n    } catch {\n        throw new CommandExecutionError('LinkedIn company extraction returned a malformed company slug');\n    }\n    return `https://${LINKEDIN_DOMAIN}/company/${encodeURIComponent(slug)}/about/`;\n}\n\nfunction normalizeCompanyInfo(info, targetUrl) {","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/linkedin/company.js#L65-L101","documentation":"normalizeCompanyOutputUrl parses the current URL reported by the in-page extraction script (or the fallback targetUrl). If the string cannot be parsed as a URL even relative to https://linkedin.com, the library assumes the extraction result is corrupt and throws rather than continuing with garbage.","triggerScenarios":"The page-extraction script returned a non-URL string for the current location (empty garbage, JSON fragments, or whitespace-only after normalization) and fallbackUrl was also unusable; page script executed in an unexpected context returning undefined coerced to 'undefined'.","commonSituations":"LinkedIn layout drift or a bot-check/login interstitial causing the extractor to grab wrong text; DOM APIs failing in the scraping context so location is read incorrectly; very old extractor output format after a library update.","solutions":["Verify the scraper session actually reached the LinkedIn company page (not a login/captcha interstitial)","Update the library in case the extractor script was fixed for a newer LinkedIn layout","Retry with an explicit valid fallbackUrl so normalization has a sane base","Log the raw extraction value to confirm what the in-page script returned"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isPlainObject(v) { return v !== null && typeof v === 'object' && !Array.isArray(v); }","tryCatchPattern":"try {\n  const info = await company({ url: target });\n} catch (err) {\n  if (String(err.message).includes('malformed current URL')) {\n    // inspect raw extractor output / retry with a fresh session\n    return retryWithFallback(target);\n  }\n  throw err;\n}","preventionTips":["Keep the library updated so the injected extractor matches current LinkedIn DOM","Ensure the scraping session reaches the page fully before extraction","Log raw extraction values in a debug mode to catch corrupt output early"],"tags":["scraping","linkedin","malformed-output"],"backgroundTag":"scrape-extraction-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}