{"id":24438911,"url":"https://github.com/vrknetha/playwright-geolocation-mock","last_synced_at":"2026-02-08T18:02:01.961Z","repository":{"id":266653974,"uuid":"898909630","full_name":"vrknetha/playwright-geolocation-mock","owner":"vrknetha","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-05T11:33:13.000Z","size":97,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-17T08:18:38.959Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vrknetha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-12-05T09:12:39.000Z","updated_at":"2024-12-06T05:37:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"bf92a096-3a9b-4f61-b31a-dbb38fb019f2","html_url":"https://github.com/vrknetha/playwright-geolocation-mock","commit_stats":null,"previous_names":["vrknetha/playwright-geolocation-mock"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/vrknetha/playwright-geolocation-mock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrknetha%2Fplaywright-geolocation-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrknetha%2Fplaywright-geolocation-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrknetha%2Fplaywright-geolocation-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrknetha%2Fplaywright-geolocation-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vrknetha","download_url":"https://codeload.github.com/vrknetha/playwright-geolocation-mock/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrknetha%2Fplaywright-geolocation-mock/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265966092,"owners_count":23857056,"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","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":[],"created_at":"2025-01-20T19:18:09.392Z","updated_at":"2026-02-08T18:02:01.865Z","avatar_url":"https://github.com/vrknetha.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Playwright Geolocation Mock\n\nA comprehensive geolocation mocking utility for Playwright testing. This package allows you to easily mock geolocation data in your Playwright tests, including single locations, routes, and error scenarios.\n\n## Features\n\n- Mock single location with customizable accuracy\n- Simulate movement along routes\n- Mock geolocation errors\n- Control geolocation permissions\n- 35+ predefined locations across continents and landmarks\n- TypeScript support\n- Cross-browser support (Chrome, Firefox, Safari)\n- Mobile browser support\n\n## Installation\n\n```bash\nnpm install --save-dev playwright-geolocation-mock\n```\n\n## Usage\n\n### Basic Location Mocking\n\n```typescript\nimport { test } from '@playwright/test';\nimport { GeoMocker, PREDEFINED_LOCATIONS } from 'playwright-geolocation-mock';\n\ntest('mock user location', async ({ context, page }) =\u003e {\n  const geo = new GeoMocker(context);\n  \n  // Use predefined locations\n  await geo.mockLocation(PREDEFINED_LOCATIONS.LONDON);          // Cities\n  await geo.mockLocation(PREDEFINED_LOCATIONS.EIFFEL_TOWER);    // Landmarks\n  await geo.mockLocation(PREDEFINED_LOCATIONS.SILICON_VALLEY);  // Tech Hubs\n  \n  // Or specify custom location\n  await geo.mockLocation({\n    latitude: 51.5074,\n    longitude: -0.1278,\n    accuracy: 10 // optional, in meters\n  });\n});\n```\n\n### Route Simulation\n\n```typescript\ntest('simulate movement', async ({ context, page }) =\u003e {\n  const geo = new GeoMocker(context);\n  \n  // Simulate a European tour\n  await geo.mockRoute([\n    PREDEFINED_LOCATIONS.LONDON,\n    PREDEFINED_LOCATIONS.PARIS,\n    PREDEFINED_LOCATIONS.BERLIN,\n    PREDEFINED_LOCATIONS.ROME,\n    PREDEFINED_LOCATIONS.MADRID\n  ], {\n    interval: 3000, // Update every 3 seconds\n    loop: false     // Stop at the last position\n  });\n\n  // Or simulate a world tech hub tour\n  await geo.mockRoute([\n    PREDEFINED_LOCATIONS.SILICON_VALLEY,\n    PREDEFINED_LOCATIONS.BANGALORE,\n    PREDEFINED_LOCATIONS.SHENZHEN,\n    PREDEFINED_LOCATIONS.TEL_AVIV\n  ]);\n\n  // Stop route simulation if needed\n  geo.stopRoute();\n});\n```\n\n### Error Simulation\n\n```typescript\ntest('handle location errors', async ({ context, page }) =\u003e {\n  const geo = new GeoMocker(context);\n  \n  // Simulate permission denied error\n  await geo.mockError(1); // PERMISSION_DENIED = 1\n  \n  // Error codes:\n  // 1 = PERMISSION_DENIED\n  // 2 = POSITION_UNAVAILABLE\n  // 3 = TIMEOUT\n});\n```\n\n### Permission Control\n\n```typescript\ntest('manage permissions', async ({ context, page }) =\u003e {\n  const geo = new GeoMocker(context);\n  \n  // Grant geolocation permission\n  await geo.mockPermission('granted');\n  \n  // Deny permission\n  await geo.mockPermission('denied');\n  \n  // Note: When permission is granted, the last mocked location will be restored\n});\n```\n\n### High Accuracy Mode\n\n```typescript\ntest('use high accuracy mode', async ({ context, page }) =\u003e {\n  const geo = new GeoMocker(context);\n  \n  await geo.mockLocation(PREDEFINED_LOCATIONS.LONDON, {\n    enableHighAccuracy: true // Reduces accuracy value by half\n  });\n});\n```\n\n## Testing Setup\n\n### Test Fixtures\n\n```typescript\nimport { test as base } from '@playwright/test';\nimport { GeoMocker } from 'playwright-geolocation-mock';\n\ntype TestFixtures = {\n  geoMocker: GeoMocker;\n};\n\nconst test = base.extend\u003cTestFixtures\u003e({\n  geoMocker: async ({ context }, use) =\u003e {\n    const geoMocker = new GeoMocker(context);\n    await use(geoMocker);\n    geoMocker.dispose();\n  },\n});\n```\n\n## API Reference\n\n### `GeoMocker`\n\n#### Constructor\n```typescript\nconstructor(context: BrowserContext)\n```\n\n#### Methods\n\n##### `mockLocation(position: GeoPosition, options?: GeoMockOptions): Promise\u003cvoid\u003e`\nMock a single location with optional configuration.\n\n##### `mockRoute(positions: GeoPosition[], options?: RouteOptions): Promise\u003cvoid\u003e`\nSimulate movement between multiple locations.\n\n##### `mockError(code: GeoLocationErrorCode): Promise\u003cvoid\u003e`\nSimulate a geolocation error.\n\n##### `mockPermission(permission: GeolocationPermission): Promise\u003cvoid\u003e`\nControl geolocation permissions.\n\n##### `stopRoute(): void`\nStop an ongoing route simulation.\n\n##### `dispose(): void`\nClean up resources (automatically stops any active route).\n\n### Types\n\n```typescript\ninterface GeoPosition {\n  latitude: number;\n  longitude: number;\n  accuracy?: number;\n  altitude?: number | null;\n  altitudeAccuracy?: number | null;\n  heading?: number | null;\n  speed?: number | null;\n}\n\ninterface GeoMockOptions {\n  enableHighAccuracy?: boolean;\n}\n\ninterface RouteOptions {\n  interval?: number;  // Default: 1000ms\n  loop?: boolean;     // Default: false\n}\n\ntype GeolocationPermission = 'granted' | 'denied';\n\ntype GeoLocationErrorCode = 1 | 2 | 3;  // PERMISSION_DENIED | POSITION_UNAVAILABLE | TIMEOUT\n```\n\n## Browser Support\n\n- Chromium (Desktop \u0026 Mobile)\n- Firefox (Desktop)\n- WebKit/Safari (Desktop \u0026 Mobile)\n\nNote: Some features like high accuracy mode and error handling may behave differently across browsers.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nMIT \n\n## Releases\n\nRelease Title Format: `v{major}.{minor}.{patch}`\nExample: `v1.0.0`\n\nRelease Description Template:\n```markdown\n## What's Changed\n- Brief summary of major changes\n- New features added\n- Bug fixes\n- Breaking changes (if any)\n\n## New Features\n- Detailed description of new feature 1\n- Detailed description of new feature 2\n\n## Bug Fixes\n- Fixed issue with X\n- Resolved problem with Y\n\n## Breaking Changes\n- List any breaking changes\n- Migration steps if needed\n\n## Dependencies\n- Updated dependencies\n- New dependencies added\n\n## Documentation\n- Documentation updates\n- New examples added\n\n## Contributors\n@username - Feature/Fix description\n``` ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvrknetha%2Fplaywright-geolocation-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvrknetha%2Fplaywright-geolocation-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvrknetha%2Fplaywright-geolocation-mock/lists"}