Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/code/src/main/di/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ import type { UPDATE_LIFECYCLE_SERVICE } from "@posthog/core/updates/identifiers
import type { UpdatesService } from "@posthog/core/updates/updates";
import type { USAGE_HOST, UsageHost } from "@posthog/core/usage/identifiers";
import type { ROOT_LOGGER, RootLogger } from "@posthog/di/logger";
import type {
BROWSER_SERVICE,
IBrowserService,
} from "@posthog/host-router/ports/browser";
import type {
CONNECTIVITY_CLIENT,
HostConnectivityClient,
Expand Down Expand Up @@ -425,6 +429,7 @@ export interface MainBindings {
[LOGS_SERVICE]: ILogsService;
[MAIN_ENCRYPTION_SERVICE]: EncryptionService;
[MAIN_DISCORD_PRESENCE_SERVICE]: DiscordPresenceService;
[BROWSER_SERVICE]: IBrowserService;

// ws-server git service (bound to(GitService))
[WS_GIT_SERVICE]: GitService;
Expand Down
3 changes: 3 additions & 0 deletions apps/code/src/main/di/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import { USAGE_HOST } from "@posthog/core/usage/identifiers";
import { usageMonitorModule } from "@posthog/core/usage/usage-monitor.module";
import { ROOT_LOGGER, type RootLogger } from "@posthog/di/logger";
import { listFilesContainingText } from "@posthog/git/queries";
import { BROWSER_SERVICE } from "@posthog/host-router/ports/browser";
import {
GIT_PR_STATUS_PROVIDER,
type IGitPrStatus,
Expand Down Expand Up @@ -233,6 +234,7 @@ import {
OAuthFlowPortAdapter,
TokenCipherPortAdapter,
} from "../services/auth/port-adapters";
import { BrowserService } from "../services/browser/service";
import { DeepLinkService } from "../services/deep-link/service";
import { DiscordPresenceService } from "../services/discord-presence/service";
import { EncryptionService } from "../services/encryption/service";
Expand Down Expand Up @@ -700,6 +702,7 @@ container.bind(LOGS_SERVICE).toDynamicValue((ctx) => {
});
container.bind(MAIN_ENCRYPTION_SERVICE).to(EncryptionService);
container.bind(MAIN_TOKENS.DiscordPresenceService).to(DiscordPresenceService);
container.bind(BROWSER_SERVICE).to(BrowserService).inSingletonScope();

// Canvas / dashboards (project-bluebird). The host-agnostic dashboard services
// live in @posthog/core (bound via canvasCoreModule) and resolve through
Expand Down
33 changes: 33 additions & 0 deletions apps/code/src/main/services/browser/errorPage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, expect, it } from "vitest";
import { buildErrorPage } from "./errorPage";

describe("buildErrorPage", () => {
it("returns a data: URI", () => {
const result = buildErrorPage("https://example.com");
expect(result).toMatch(/^data:text\/html;charset=utf-8,/);
});

it("encodes the failed URL into the page", () => {
const url = "https://example.com/path?q=test";
const result = buildErrorPage(url);
const decoded = decodeURIComponent(
result.replace("data:text/html;charset=utf-8,", ""),
);
expect(decoded).toContain(url);
});

it("produces valid HTML with PostHog branding", () => {
const decoded = decodeURIComponent(
buildErrorPage("https://example.com").replace(
"data:text/html;charset=utf-8,",
"",
),
);
expect(decoded).toContain("<!DOCTYPE html>");
expect(decoded).toContain("PostHog");
});

it("handles empty URL without throwing", () => {
expect(() => buildErrorPage("")).not.toThrow();
});
});
56 changes: 56 additions & 0 deletions apps/code/src/main/services/browser/errorPage.ts

Large diffs are not rendered by default.

61 changes: 61 additions & 0 deletions apps/code/src/main/services/browser/newTabPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { HOG_B64 } from "./errorPage";

export function buildNewTabPage(): string {
const html = `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
background: #1a1a1a;
color: #e8e8e8;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
padding: 40px 20px;
}
.container {
text-align: center;
max-width: 460px;
}
.hog {
width: 160px;
height: auto;
margin: 0 auto 28px;
filter: drop-shadow(0 8px 32px rgba(0,0,0,.6));
}
h1 {
font-size: 24px;
font-weight: 700;
color: #fff;
letter-spacing: -0.3px;
margin-bottom: 10px;
}
p {
font-size: 14px;
line-height: 1.65;
color: #888;
max-width: 400px;
}
.footer {
margin-top: 24px;
font-size: 11px;
color: #444;
letter-spacing: 0.5px;
}
</style>
</head>
<body>
<div class="container">
<img class="hog" src="data:image/png;base64,${HOG_B64}" alt="" />
<h1>Hedge Browser</h1>
<p>A lightweight browser built right into your workspace. Check things quickly without breaking your flow.</p>
<div class="footer">you still have the option to open links in your preferred browser</div>
</div>
</body>
</html>`;
return `data:text/html;charset=utf-8,${encodeURIComponent(html)}`;
}
Loading