{"id":50460758,"url":"https://github.com/tkdeng/embed-portal","last_synced_at":"2026-06-06T05:00:54.125Z","repository":{"id":360335457,"uuid":"1249682439","full_name":"tkdeng/embed-portal","owner":"tkdeng","description":"A reimplementation of what the protal element could have been.","archived":false,"fork":false,"pushed_at":"2026-05-26T00:53:45.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-01T04:33:11.876Z","etag":null,"topics":["css","embed-portal","html","html-css-javascript","html-element","html-embed","html-embed-portal","html-portal","html5","iframe","javascript","js","shadow-dom"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tkdeng.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-26T00:29:20.000Z","updated_at":"2026-05-26T00:53:04.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/tkdeng/embed-portal","commit_stats":null,"previous_names":["tkdeng/embed-portal"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/tkdeng/embed-portal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkdeng%2Fembed-portal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkdeng%2Fembed-portal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkdeng%2Fembed-portal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkdeng%2Fembed-portal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tkdeng","download_url":"https://codeload.github.com/tkdeng/embed-portal/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkdeng%2Fembed-portal/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33969883,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-06T02:00:07.033Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css","embed-portal","html","html-css-javascript","html-element","html-embed","html-embed-portal","html-portal","html5","iframe","javascript","js","shadow-dom"],"created_at":"2026-06-01T04:30:25.571Z","updated_at":"2026-06-06T05:00:54.095Z","avatar_url":"https://github.com/tkdeng.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Embed Portal\n\nEmbed Portal is a lightweight custom element that allows you to fetch external HTML and inject it directly into a Shadow DOM.\n\nWhile it functions similarly to an `\u003ciframe\u003e`, using a Shadow DOM keeps the embedded content encapsulated within the light DOM's styling and structure without the overhead or isolation constraints of a full iframe.\n\n## Why Use It?\n\n- Encapsulation: Styles defined in the parent document won't leak into the portal (and vice versa).\n- Performance: Avoids the heavy resource usage associated with loading multiple independent browser contexts (iframes).\n- Seamless Integration: Allows you to fetch and display modular components or partial pages dynamically.\n\n## Installation\n\nAdd this script to your project:\n\n```html\n\u003clink rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/gh/tkdeng/embed-portal/style.min.css\"/\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/gh/tkdeng/embed-portal/script.min.js\" defer\u003e\u003c/script\u003e\n```\n\n## Usage\n\nSimply use the `\u003cembed-portal\u003e` tag in your HTML:\n\n```html\n\u003cembed-portal src=\"/embed-shadow-dom\"\u003e\u003c/embed-portal\u003e\n```\n\n### Handling Events\n\nYou can react to the portal's lifecycle using standard event listeners:\n\n```js\nconst portal = document.querySelector('embed-portal');\n\n// Handle successful load\nportal.addEventListener('load', (event) =\u003e {\n  console.log('Portal content injected successfully!');\n\n  // Access the shadow root directly from the event\n  const shadowRoot = event.detail.root;\n});\n\n// Handle errors\nportal.addEventListener('error', (event) =\u003e {\n  console.error('Failed to load portal:', event.detail.message);\n});\n```\n\n## Attributes\n\n| Attribute | Description |\n| --------- | ----------- |\n| src | The URL of the HTML content to embed (must be same-origin). |\n| noscript | Optional. If present, prevents the script from attempting to extract and execute `\u003cscript\u003e` tags from the fetched content. |\n| onload | Optional. A string containing JavaScript to execute once the content has been successfully injected. |\n\n## How It Works\n\n1. Polling: The script periodically scans the DOM for new `\u003cembed-portal\u003e` elements.\n2. Fetching: It performs a GET request to the provided src with a custom X-Fetch-Dest: embed-portal header.\n3. Parsing: It extracts `\u003clink\u003e` stylesheets and `\u003cstyle\u003e` blocks from the document head and injects them into the Shadow DOM to preserve styling.\n4. Injection: It extracts the `\u003cbody\u003e` content and appends it into the shadow root.\n5. Events: Once loaded, it dispatches a custom `load` event containing the `shadow` root in the `detail` object (or `error` if the request fails).\n\n## Technical Notes\n\n- Security: This implementation enforces same-origin requests to prevent CORS issues. Invalid requests trigger an `error` event and log a sanitized URL to the console.\n- Script Handling: By default, it attempts to extract and register scripts from the fetched page to the main document head. You can disable this with the `noscript` attribute.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftkdeng%2Fembed-portal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftkdeng%2Fembed-portal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftkdeng%2Fembed-portal/lists"}