{"id":20053259,"url":"https://github.com/mcomella/github-content-script-navigation","last_synced_at":"2025-08-04T12:40:23.367Z","repository":{"id":145122691,"uuid":"136693042","full_name":"mcomella/github-content-script-navigation","owner":"mcomella","description":"Fixes WebExtensions content script navigation on GitHub.com","archived":false,"fork":false,"pushed_at":"2018-06-09T05:46:07.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-02T09:14:14.777Z","etag":null,"topics":["content-script","github","webextensions"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mcomella.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}},"created_at":"2018-06-09T05:17:05.000Z","updated_at":"2021-05-18T10:12:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"e0509ea9-a956-487a-b52b-342d46f2b554","html_url":"https://github.com/mcomella/github-content-script-navigation","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/mcomella/github-content-script-navigation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcomella%2Fgithub-content-script-navigation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcomella%2Fgithub-content-script-navigation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcomella%2Fgithub-content-script-navigation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcomella%2Fgithub-content-script-navigation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcomella","download_url":"https://codeload.github.com/mcomella/github-content-script-navigation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcomella%2Fgithub-content-script-navigation/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268697184,"owners_count":24292394,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-04T02:00:09.867Z","response_time":79,"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":["content-script","github","webextensions"],"created_at":"2024-11-13T12:24:05.952Z","updated_at":"2025-08-04T12:40:23.323Z","avatar_url":"https://github.com/mcomella.png","language":"JavaScript","readme":"# GitHub Content Script Navigation\nContent scripts on GitHub don't work as expected: content scripts ordinarily\nreload for each new page visited but, on GitHub, they don't. This is because\nlinks on GitHub mutate the DOM and use the [history.pushState API][], instead of\nloading pages the standard way, which creates an entirely new DOM. We fix this\nby adding a MutationObserver that will check when the DOM has been updated,\nthus indicating that the new page has been loaded from a user's perspective,\nand notify the WebExtension about this event.\n\n## Usage\nTo use this fix, copy `github_navigation.js` into your project. In your\n`manifest.json`, add it as a content script after your other content script files:\n```json\n\"content_scripts\": [{\n   \"matches\": [\"*://*.github.com/*\"],\n   \"js\": [\"content_script.js\", \"github_navigation.js\"]\n }],\n```\n\nIn another content script file, define an `onPageLoad` function:\n```js\nfunction onPageLoad() {\n    // Code to run when the page loads\n}\n```\n\n`onPageLoad` will be called when a new page loads, i.e. when the\ncontent script is first loaded and when the history.pushState APIs\nare used.\n\nSee [the sample][] for more details.\n\n### Caveats\nSome pages will have additional async events (e.g. the Milestone page loads issues\nasynchronously) so it may be necessary to add additional logic to check for page\nload completion.\n\n**Important:** this implementation is fragile. It relies on the structure of the\nGitHub website, which is subject to change.\n\n## Alternatives\nThe seemingly \"correct\" approach would be to create a `history.pushState`\nobserver using [the `webNavigation.onHistoryStateUpdated` listener][hist listener].\nHowever, this listener does not work as expected: it's called twice -- once\nbefore the DOM has been mutated and once after -- and I haven't found a good\nway to distinguish them other than to look at changes in the DOM, which is\nalready the approach this solution takes.\n\n## License\nThe license for this repository is the X11 license, which is similar to the MIT license.\n\n[the sample]: https://github.com/mcomella/github-content-script-navigation/tree/master/sample\n[history.pushState API]: https://developer.mozilla.org/en-US/docs/Web/API/History_API#The_pushState()_method\n[hist listener]: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/webNavigation/onHistoryStateUpdated\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcomella%2Fgithub-content-script-navigation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcomella%2Fgithub-content-script-navigation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcomella%2Fgithub-content-script-navigation/lists"}