firebase-tools 15.35.0 → 15.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/appcheck/debugTokens.js +293 -0
- package/lib/appcheck/localConfig.js +191 -0
- package/lib/appdistribution/options-parser-util.js +1 -1
- package/lib/apphosting/githubConnections.js +1 -1
- package/lib/auth.js +8 -2
- package/lib/commands/appcheck-debugtokens-create.js +60 -35
- package/lib/commands/appcheck-debugtokens-delete.js +21 -7
- package/lib/commands/appcheck-debugtokens-list.js +37 -8
- package/lib/commands/appcheck-debugtokens-prune.js +59 -0
- package/lib/commands/crashlytics-heapdumps-status.js +1 -1
- package/lib/commands/deploy.js +1 -3
- package/lib/commands/hosting-channel-create.js +1 -3
- package/lib/commands/hosting-channel-delete.js +1 -3
- package/lib/commands/hosting-channel-deploy.js +1 -3
- package/lib/commands/hosting-channel-list.js +1 -3
- package/lib/commands/hosting-channel-open.js +1 -3
- package/lib/commands/hosting-clone.js +3 -5
- package/lib/commands/hosting-disable.js +2 -2
- package/lib/commands/hosting-sites-create.js +1 -3
- package/lib/commands/hosting-sites-delete.js +1 -3
- package/lib/commands/hosting-sites-get.js +1 -3
- package/lib/commands/hosting-sites-list.js +1 -3
- package/lib/commands/index.js +1 -0
- package/lib/crashlytics/events.js +122 -1
- package/lib/crashlytics/filters.js +12 -6
- package/lib/crashlytics/profilingManager.js +14 -34
- package/lib/crashlytics/utils.js +14 -0
- package/lib/database/import.js +5 -4
- package/lib/dataconnect/names.js +3 -3
- package/lib/dataconnect/schemaMigration.js +1 -1
- package/lib/deploy/functions/backend.js +0 -10
- package/lib/deploy/functions/cel.js +1 -1
- package/lib/deploy/functions/release/reporter.js +0 -26
- package/lib/deploy/functions/runtimes/discovery/index.js +4 -1
- package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +1 -1
- package/lib/deploy/functions/services/index.js +13 -11
- package/lib/deploy/hosting/prepare.js +1 -3
- package/lib/deploy/lifecycleHooks.js +1 -1
- package/lib/emulator/auth/operations.js +2 -2
- package/lib/emulator/auth/server.js +4 -2
- package/lib/emulator/auth/widget_ui.js +1 -1
- package/lib/emulator/commandUtils.js +4 -1
- package/lib/emulator/databaseEmulator.js +16 -11
- package/lib/emulator/dataconnect/pgliteServer.js +30 -24
- package/lib/emulator/downloadableEmulatorInfo.json +24 -24
- package/lib/emulator/downloadableEmulators.js +2 -2
- package/lib/emulator/extensions/postinstall.js +6 -6
- package/lib/emulator/firestoreEmulator.js +21 -15
- package/lib/emulator/functionsEmulator.js +11 -7
- package/lib/emulator/functionsEmulatorRuntime.js +7 -2
- package/lib/emulator/hub.js +12 -8
- package/lib/emulator/shared/express.js +30 -0
- package/lib/emulator/storage/apis/firebase.js +11 -10
- package/lib/emulator/storage/apis/gcloud.js +21 -20
- package/lib/emulator/storage/files.js +1 -1
- package/lib/emulator/storage/rules/manager.js +15 -12
- package/lib/emulator/storage/server.js +10 -5
- package/lib/extensions/extensionsHelper.js +2 -2
- package/lib/extensions/paramHelper.js +1 -1
- package/lib/extensions/provisioningHelper.js +1 -6
- package/lib/firestore/util.js +3 -3
- package/lib/frameworks/angular/utils.js +1 -1
- package/lib/frameworks/next/utils.js +1 -1
- package/lib/functions/kits/install.js +221 -316
- package/lib/functions/kits/sources/directory.js +32 -0
- package/lib/functions/kits/sources/npm.js +55 -5
- package/lib/functionsConfig.js +0 -4
- package/lib/functionsShellCommandAction.js +1 -1
- package/lib/gcp/cloudfunctionsv2.js +0 -6
- package/lib/gcp/devConnect.js +2 -2
- package/lib/hosting/api.js +79 -0
- package/lib/hosting/proxy.js +4 -1
- package/lib/init/features/hosting/github.js +6 -4
- package/lib/init/features/hosting/index.js +4 -0
- package/lib/mcp/apps/init/mcp-app.js +4 -1
- package/lib/mcp/index.js +8 -2
- package/lib/mcp/prompts/apptesting/run_test.js +3 -3
- package/lib/mcp/prompts/core/deploy.js +3 -3
- package/lib/mcp/resources/guides/init_ai.js +10 -10
- package/lib/mcp/tools/crashlytics/events.js +18 -93
- package/lib/mcp/tools/crashlytics/index.js +2 -0
- package/lib/mcp/tools/crashlytics/reports.js +1 -1
- package/lib/mcp/tools/crashlytics/setup.js +392 -0
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/lib/utils.js +4 -10
- package/package.json +1 -1
- package/lib/functions/kits/sources/index.js +0 -19
|
@@ -5,103 +5,18 @@ const js_yaml_1 = require("js-yaml");
|
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
6
|
const events_1 = require("../../../crashlytics/events");
|
|
7
7
|
const filters_1 = require("../../../crashlytics/filters");
|
|
8
|
-
const types_1 = require("../../../crashlytics/types");
|
|
9
8
|
const app_id_1 = require("../../resources/guides/app_id");
|
|
10
9
|
const tool_1 = require("../../tool");
|
|
11
|
-
const DUMP_OPTIONS = { lineWidth: 200 };
|
|
12
|
-
function formatFrames(origFrames, maxFrames = 20) {
|
|
13
|
-
const frames = origFrames || [];
|
|
14
|
-
const shouldTruncate = frames.length > maxFrames;
|
|
15
|
-
const framesToFormat = shouldTruncate ? frames.slice(0, maxFrames - 1) : frames;
|
|
16
|
-
const formatted = framesToFormat.map((frame) => {
|
|
17
|
-
let line = `at`;
|
|
18
|
-
if (frame.symbol) {
|
|
19
|
-
line += ` ${frame.symbol}`;
|
|
20
|
-
}
|
|
21
|
-
if (frame.file) {
|
|
22
|
-
line += ` (${frame.file}`;
|
|
23
|
-
if (frame.line) {
|
|
24
|
-
line += `:${frame.line}`;
|
|
25
|
-
}
|
|
26
|
-
line += ")";
|
|
27
|
-
}
|
|
28
|
-
return line;
|
|
29
|
-
});
|
|
30
|
-
if (shouldTruncate) {
|
|
31
|
-
formatted.push("... frames omitted ...");
|
|
32
|
-
}
|
|
33
|
-
return formatted;
|
|
34
|
-
}
|
|
35
|
-
function toText(event) {
|
|
36
|
-
if (!event) {
|
|
37
|
-
return {};
|
|
38
|
-
}
|
|
39
|
-
const result = {};
|
|
40
|
-
for (const [key, value] of Object.entries(event)) {
|
|
41
|
-
if (key === "logs") {
|
|
42
|
-
const logs = value || [];
|
|
43
|
-
const slicedLogs = logs.length > 100 ? logs.slice(logs.length - 100) : logs;
|
|
44
|
-
const logLines = slicedLogs.map((log) => `[${log.logTime}] ${log.message}`);
|
|
45
|
-
result["logs"] = logLines.join("\n");
|
|
46
|
-
}
|
|
47
|
-
else if (key === "breadcrumbs") {
|
|
48
|
-
const breadcrumbs = value || [];
|
|
49
|
-
const slicedBreadcrumbs = breadcrumbs.length > 10 ? breadcrumbs.slice(-10) : breadcrumbs;
|
|
50
|
-
const breadcrumbLines = slicedBreadcrumbs.map((b) => {
|
|
51
|
-
const paramString = Object.entries(b?.params || {})
|
|
52
|
-
.map(([k, v]) => `${k}: ${v}`)
|
|
53
|
-
.join(", ");
|
|
54
|
-
const params = paramString ? ` { ${paramString} }` : "";
|
|
55
|
-
return `[${b.eventTime}] ${b.title}${params}`;
|
|
56
|
-
});
|
|
57
|
-
result["breadcrumbs"] = breadcrumbLines.join("\n");
|
|
58
|
-
}
|
|
59
|
-
else if (key === "threads") {
|
|
60
|
-
let threads = value || [];
|
|
61
|
-
if (event.issue?.errorType === types_1.ErrorType.FATAL || event.issue?.errorType === types_1.ErrorType.ANR) {
|
|
62
|
-
threads = threads.filter((t) => t.crashed || t.blamed);
|
|
63
|
-
}
|
|
64
|
-
const threadStrings = threads.map((thread) => {
|
|
65
|
-
const header = `Thread: ${thread.name || thread.threadId || ""}${thread.crashed ? " (crashed)" : ""}`;
|
|
66
|
-
const frameStrings = formatFrames(thread.frames || []);
|
|
67
|
-
return [header, ...frameStrings].join("\n");
|
|
68
|
-
});
|
|
69
|
-
result["threads"] = threadStrings.join("\n\n");
|
|
70
|
-
}
|
|
71
|
-
else if (key === "exceptions") {
|
|
72
|
-
const exceptions = value || [];
|
|
73
|
-
const exceptionStrings = exceptions.map((exception) => {
|
|
74
|
-
const header = exception.nested ? "Caused by: " : "";
|
|
75
|
-
const exceptionHeader = `${header}${exception.type || ""}: ${exception.exceptionMessage || ""}`;
|
|
76
|
-
const frameStrings = formatFrames(exception.frames || []);
|
|
77
|
-
return [exceptionHeader, ...frameStrings].join("\n");
|
|
78
|
-
});
|
|
79
|
-
result["exceptions"] = exceptionStrings.join("\n\n");
|
|
80
|
-
}
|
|
81
|
-
else if (key === "errors") {
|
|
82
|
-
const errors = value || [];
|
|
83
|
-
const errorStrings = errors.map((error) => {
|
|
84
|
-
const header = `Error: ${error.title || "error"}`;
|
|
85
|
-
const frameStrings = formatFrames(error.frames || []);
|
|
86
|
-
return [header, ...frameStrings].join("\n");
|
|
87
|
-
});
|
|
88
|
-
result["errors"] = errorStrings.join("\n\n");
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
result[key] = (0, js_yaml_1.dump)(value, DUMP_OPTIONS);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return result;
|
|
95
|
-
}
|
|
96
10
|
exports.list_events = (0, tool_1.tool)("crashlytics", {
|
|
97
11
|
name: "list_events",
|
|
98
|
-
description: `Use this to list the most recent events matching the given filters.
|
|
12
|
+
description: `Use this to list the most recent events matching the given filters, including custom key filter expressions.
|
|
99
13
|
Can be used to fetch sample crashes and exceptions for an issue,
|
|
100
14
|
which will include stack traces and other data useful for debugging.`,
|
|
101
15
|
humanReadableDescription: "List recent crash and exception events matching specified filters for an issue.",
|
|
102
16
|
inputSchema: zod_1.z.object({
|
|
103
17
|
appId: filters_1.ApplicationIdSchema,
|
|
104
18
|
filter: filters_1.EventFilterSchema,
|
|
19
|
+
filterExpression: filters_1.FilterExpressionSchema,
|
|
105
20
|
pageSize: zod_1.z.number().describe("Number of rows to return").default(1),
|
|
106
21
|
}),
|
|
107
22
|
annotations: {
|
|
@@ -111,7 +26,7 @@ exports.list_events = (0, tool_1.tool)("crashlytics", {
|
|
|
111
26
|
_meta: {
|
|
112
27
|
requiresAuth: true,
|
|
113
28
|
},
|
|
114
|
-
}, async ({ appId, filter, pageSize }) => {
|
|
29
|
+
}, async ({ appId, filter, filterExpression, pageSize }) => {
|
|
115
30
|
const result = { content: [] };
|
|
116
31
|
if (!appId) {
|
|
117
32
|
result.isError = true;
|
|
@@ -125,13 +40,23 @@ exports.list_events = (0, tool_1.tool)("crashlytics", {
|
|
|
125
40
|
text: `Must specify 'filter.issueId' or 'filter.issueVariantId' parameters.`,
|
|
126
41
|
});
|
|
127
42
|
}
|
|
43
|
+
else {
|
|
44
|
+
try {
|
|
45
|
+
filter = (0, filters_1.validateEventFilters)(filter, appId);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
49
|
+
result.isError = true;
|
|
50
|
+
result.content.push({ type: "text", text: `Error: ${message}` });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
128
53
|
if (result.content.length > 0) {
|
|
129
54
|
return result;
|
|
130
55
|
}
|
|
131
|
-
const response = await (0, events_1.listEvents)(appId, filter, pageSize);
|
|
132
|
-
const eventsContent = response.events?.map((e) => toText(e)) || [];
|
|
56
|
+
const response = await (0, events_1.listEvents)(appId, filter, pageSize, filterExpression);
|
|
57
|
+
const eventsContent = response.events?.map((e) => (0, events_1.toText)(e)) || [];
|
|
133
58
|
return {
|
|
134
|
-
content: [{ type: "text", text: (0, js_yaml_1.dump)(eventsContent,
|
|
59
|
+
content: [{ type: "text", text: (0, js_yaml_1.dump)(eventsContent, events_1.EVENT_DUMP_OPTIONS) }],
|
|
135
60
|
};
|
|
136
61
|
});
|
|
137
62
|
exports.batch_get_events = (0, tool_1.tool)("crashlytics", {
|
|
@@ -171,8 +96,8 @@ exports.batch_get_events = (0, tool_1.tool)("crashlytics", {
|
|
|
171
96
|
return result;
|
|
172
97
|
}
|
|
173
98
|
const response = await (0, events_1.batchGetEvents)(appId, names);
|
|
174
|
-
const eventsContent = response.events?.map((e) => toText(e)) || [];
|
|
99
|
+
const eventsContent = response.events?.map((e) => (0, events_1.toText)(e)) || [];
|
|
175
100
|
return {
|
|
176
|
-
content: [{ type: "text", text: (0, js_yaml_1.dump)(eventsContent,
|
|
101
|
+
content: [{ type: "text", text: (0, js_yaml_1.dump)(eventsContent, events_1.EVENT_DUMP_OPTIONS) }],
|
|
177
102
|
};
|
|
178
103
|
});
|
|
@@ -5,6 +5,7 @@ const notes_1 = require("./notes");
|
|
|
5
5
|
const issues_1 = require("./issues");
|
|
6
6
|
const events_1 = require("./events");
|
|
7
7
|
const reports_1 = require("./reports");
|
|
8
|
+
const setup_1 = require("./setup");
|
|
8
9
|
exports.crashlyticsTools = [
|
|
9
10
|
notes_1.create_note,
|
|
10
11
|
notes_1.delete_note,
|
|
@@ -14,4 +15,5 @@ exports.crashlyticsTools = [
|
|
|
14
15
|
notes_1.list_notes,
|
|
15
16
|
reports_1.get_report,
|
|
16
17
|
issues_1.update_issue,
|
|
18
|
+
setup_1.setup,
|
|
17
19
|
];
|
|
@@ -41,7 +41,7 @@ exports.get_report = (0, tool_1.tool)("crashlytics", {
|
|
|
41
41
|
result.content.push({ type: "text", text: app_id_1.RESOURCE_CONTENT });
|
|
42
42
|
}
|
|
43
43
|
try {
|
|
44
|
-
filter = (0, filters_1.validateEventFilters)(filter || {});
|
|
44
|
+
filter = (0, filters_1.validateEventFilters)(filter || {}, appId);
|
|
45
45
|
}
|
|
46
46
|
catch (error) {
|
|
47
47
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setup = exports.SUPPORTED_FRAMEWORKS = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const apps_1 = require("../../../management/apps");
|
|
6
|
+
const logger_1 = require("../../../logger");
|
|
7
|
+
const tool_1 = require("../../tool");
|
|
8
|
+
const util_1 = require("../../util");
|
|
9
|
+
const PLACEHOLDER_PROJECT_ID = "<YOUR_FIREBASE_PROJECT_ID>";
|
|
10
|
+
const PLACEHOLDER_APP_ID = "<YOUR_FIREBASE_APP_ID>";
|
|
11
|
+
const PLACEHOLDER_API_KEY = "<YOUR_FIREBASE_API_KEY>";
|
|
12
|
+
const PLACEHOLDER_AUTH_DOMAIN = "<YOUR_AUTH_DOMAIN>";
|
|
13
|
+
const PLACEHOLDER_STORAGE_BUCKET = "<YOUR_STORAGE_BUCKET>";
|
|
14
|
+
const PLACEHOLDER_MESSAGING_SENDER_ID = "<YOUR_MESSAGING_SENDER_ID>";
|
|
15
|
+
exports.SUPPORTED_FRAMEWORKS = [
|
|
16
|
+
"nextjs",
|
|
17
|
+
"react",
|
|
18
|
+
"react-router",
|
|
19
|
+
"tanstack",
|
|
20
|
+
"angular",
|
|
21
|
+
];
|
|
22
|
+
const FrameworkSchema = zod_1.z
|
|
23
|
+
.enum(exports.SUPPORTED_FRAMEWORKS)
|
|
24
|
+
.optional()
|
|
25
|
+
.describe("The web framework used ('nextjs', 'react', 'react-router', 'tanstack', or 'angular'). If provided, framework-specific code snippets and instructions are returned.");
|
|
26
|
+
const FRAMEWORK_GUIDES = {
|
|
27
|
+
nextjs: `### Next.js Setup Guide
|
|
28
|
+
|
|
29
|
+
#### Option A: Next.js 15.3+ (Recommended: Client Instrumentation)
|
|
30
|
+
Next.js 15.3+ supports client instrumentation via \`instrumentation-client.ts\` (or \`.js\`). This runs in the browser before React hydration begins and automatically registers global error listeners.
|
|
31
|
+
|
|
32
|
+
Create \`src/instrumentation-client.ts\` (or in project root if not using a \`src/\` directory):
|
|
33
|
+
\`\`\`typescript
|
|
34
|
+
import { getCrashlytics } from 'firebase/crashlytics';
|
|
35
|
+
import { app } from './lib/firebase'; // Shared initialization script
|
|
36
|
+
|
|
37
|
+
getCrashlytics(app);
|
|
38
|
+
\`\`\`
|
|
39
|
+
|
|
40
|
+
#### Option B: Next.js < 15.3 (Client Component Wrapper)
|
|
41
|
+
For Next.js versions earlier than 15.3, \`layout.tsx\` is a Server Component. Create a Client Component (e.g., \`src/components/CrashlyticsProvider.tsx\`):
|
|
42
|
+
\`\`\`tsx
|
|
43
|
+
'use client';
|
|
44
|
+
|
|
45
|
+
import React from 'react';
|
|
46
|
+
import { FirebaseCrashlytics } from 'firebase/crashlytics/react';
|
|
47
|
+
import { app } from '../lib/firebase'; // Shared initialization script
|
|
48
|
+
|
|
49
|
+
export function CrashlyticsProvider({ children }: { children: React.ReactNode }) {
|
|
50
|
+
return (
|
|
51
|
+
<FirebaseCrashlytics firebaseApp={app}>
|
|
52
|
+
{children}
|
|
53
|
+
</FirebaseCrashlytics>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
\`\`\`
|
|
57
|
+
|
|
58
|
+
Then wrap your application tree in \`src/app/layout.tsx\`:
|
|
59
|
+
\`\`\`tsx
|
|
60
|
+
import { CrashlyticsProvider } from '../components/CrashlyticsProvider';
|
|
61
|
+
|
|
62
|
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
63
|
+
return (
|
|
64
|
+
<html lang="en">
|
|
65
|
+
<body>
|
|
66
|
+
<CrashlyticsProvider>
|
|
67
|
+
{children}
|
|
68
|
+
</CrashlyticsProvider>
|
|
69
|
+
</body>
|
|
70
|
+
</html>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
\`\`\``,
|
|
74
|
+
react: `### React Setup Guide (without React Router)
|
|
75
|
+
|
|
76
|
+
Wrap your root application component (typically \`src/App.tsx\` or \`src/main.tsx\`) with \`<FirebaseCrashlytics>\`. It acts as the global window receiver, handling unhandled rejections and browser exceptions:
|
|
77
|
+
|
|
78
|
+
\`\`\`tsx
|
|
79
|
+
import React from 'react';
|
|
80
|
+
import { FirebaseCrashlytics } from 'firebase/crashlytics/react';
|
|
81
|
+
import { app } from './lib/firebase'; // Shared initialization script
|
|
82
|
+
|
|
83
|
+
export default function App() {
|
|
84
|
+
return (
|
|
85
|
+
<FirebaseCrashlytics firebaseApp={app}>
|
|
86
|
+
{/* Rest of your application components */}
|
|
87
|
+
</FirebaseCrashlytics>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
\`\`\`
|
|
91
|
+
|
|
92
|
+
> **Note**: If you use custom error boundaries in your application, you can also record caught errors manually via \`recordError(getCrashlytics(app), error)\`.`,
|
|
93
|
+
"react-router": `### React Router (v6+) Setup Guide
|
|
94
|
+
|
|
95
|
+
If your application uses React Router (v6+), replace React Router's \`<Routes>\` component with \`<CrashlyticsRoutes>\`. This handles uncaught errors across routes and tracks errors using parameterized templates (e.g., \`/profile/:userId\`):
|
|
96
|
+
|
|
97
|
+
\`\`\`tsx
|
|
98
|
+
import React from 'react';
|
|
99
|
+
import { BrowserRouter, Route } from 'react-router-dom';
|
|
100
|
+
import { CrashlyticsRoutes } from 'firebase/crashlytics/react-router';
|
|
101
|
+
import { app } from './lib/firebase'; // Shared initialization script
|
|
102
|
+
import Home from './pages/Home';
|
|
103
|
+
import Profile from './pages/Profile';
|
|
104
|
+
|
|
105
|
+
export default function App() {
|
|
106
|
+
return (
|
|
107
|
+
<BrowserRouter>
|
|
108
|
+
<CrashlyticsRoutes firebaseApp={app}>
|
|
109
|
+
<Route path="/" element={<Home />} />
|
|
110
|
+
<Route path="/profile/:userId" element={<Profile />} />
|
|
111
|
+
</CrashlyticsRoutes>
|
|
112
|
+
</BrowserRouter>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
\`\`\``,
|
|
116
|
+
tanstack: `### TanStack Router Setup Guide
|
|
117
|
+
|
|
118
|
+
Initialize Crashlytics with \`getCrashlytics(app)\` and pass errors from \`defaultOnCatch\` to \`recordError\`:
|
|
119
|
+
|
|
120
|
+
\`\`\`typescript
|
|
121
|
+
import { recordError, getCrashlytics } from 'firebase/crashlytics';
|
|
122
|
+
import { app } from './lib/firebase'; // Shared initialization script
|
|
123
|
+
import { createRouter } from '@tanstack/react-router';
|
|
124
|
+
import { routeTree } from './routeTree.gen';
|
|
125
|
+
|
|
126
|
+
const crashlytics = getCrashlytics(app);
|
|
127
|
+
|
|
128
|
+
const router = createRouter({
|
|
129
|
+
routeTree,
|
|
130
|
+
defaultOnCatch: (error, errorInfo) => {
|
|
131
|
+
recordError(crashlytics, error, errorInfo);
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
\`\`\`
|
|
135
|
+
|
|
136
|
+
> **Tip**: Calling \`getCrashlytics(app)\` automatically registers global listeners for uncaught window errors and unhandled promise rejections, while \`defaultOnCatch\` captures errors caught during routing and rendering.`,
|
|
137
|
+
angular: `### Angular Setup Guide
|
|
138
|
+
|
|
139
|
+
Integrate with Angular's global error-catching runtime and route tracking by adding \`provideCrashlytics(() => app)\` to your application's providers in \`src/app/app.config.ts\`:
|
|
140
|
+
|
|
141
|
+
\`\`\`typescript
|
|
142
|
+
import { ApplicationConfig } from '@angular/core';
|
|
143
|
+
import { provideRouter } from '@angular/router';
|
|
144
|
+
import { provideCrashlytics } from 'firebase/crashlytics/angular';
|
|
145
|
+
import { app } from '../lib/firebase'; // Shared initialization script
|
|
146
|
+
import { routes } from './app.routes';
|
|
147
|
+
|
|
148
|
+
export const appConfig: ApplicationConfig = {
|
|
149
|
+
providers: [
|
|
150
|
+
provideRouter(routes),
|
|
151
|
+
provideCrashlytics(() => app),
|
|
152
|
+
],
|
|
153
|
+
};
|
|
154
|
+
\`\`\`
|
|
155
|
+
|
|
156
|
+
> \`provideCrashlytics()\` registers a custom \`ErrorHandler\` to track uncaught zone crashes and uses internal \`Router\` instances to build dynamic routes rather than logging literal URLs.`,
|
|
157
|
+
};
|
|
158
|
+
function getFrameworkSection(framework) {
|
|
159
|
+
if (framework && framework in FRAMEWORK_GUIDES) {
|
|
160
|
+
return FRAMEWORK_GUIDES[framework];
|
|
161
|
+
}
|
|
162
|
+
return exports.SUPPORTED_FRAMEWORKS.map((fw) => FRAMEWORK_GUIDES[fw]).join("\n\n---\n\n");
|
|
163
|
+
}
|
|
164
|
+
async function resolveWebConfig(appIdInput, projectId) {
|
|
165
|
+
let resolvedAppId = appIdInput;
|
|
166
|
+
let detectedAppsNote;
|
|
167
|
+
let appPlatform;
|
|
168
|
+
if (appIdInput) {
|
|
169
|
+
if (appIdInput.includes(":web:")) {
|
|
170
|
+
appPlatform = apps_1.AppPlatform.WEB;
|
|
171
|
+
}
|
|
172
|
+
else if (appIdInput.includes(":android:")) {
|
|
173
|
+
appPlatform = apps_1.AppPlatform.ANDROID;
|
|
174
|
+
}
|
|
175
|
+
else if (appIdInput.includes(":ios:")) {
|
|
176
|
+
appPlatform = apps_1.AppPlatform.IOS;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (projectId) {
|
|
180
|
+
try {
|
|
181
|
+
const apps = await (0, apps_1.listFirebaseApps)(projectId, apps_1.AppPlatform.ANY);
|
|
182
|
+
if (appIdInput) {
|
|
183
|
+
const matchedApp = apps.find((a) => a.appId === appIdInput);
|
|
184
|
+
if (matchedApp) {
|
|
185
|
+
appPlatform = matchedApp.platform;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
const webApps = apps.filter((a) => a.platform === apps_1.AppPlatform.WEB || a.appId.includes(":web:"));
|
|
190
|
+
if (apps.length > 0 && webApps.length === 0) {
|
|
191
|
+
return {
|
|
192
|
+
error: `Crashlytics setup is currently only supported for Web apps. No Web apps found in project '${projectId}'. For Android and iOS, Crashlytics is configured directly in your app's build configuration (Gradle or CocoaPods/SPM).`,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
if (webApps.length === 1) {
|
|
196
|
+
resolvedAppId = webApps[0].appId;
|
|
197
|
+
}
|
|
198
|
+
else if (webApps.length > 1) {
|
|
199
|
+
resolvedAppId = webApps[0].appId;
|
|
200
|
+
detectedAppsNote = `Multiple web apps found in project '${projectId}'. Defaulting to ${resolvedAppId} (${apps[0].displayName || "unnamed"}). Other detected web apps: ${apps
|
|
201
|
+
.slice(1)
|
|
202
|
+
.map((a) => `${a.appId} (${a.displayName || "unnamed"})`)
|
|
203
|
+
.join(", ")}.`;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
catch (err) {
|
|
208
|
+
logger_1.logger.debug("Failed to list web apps for project:", err);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (appIdInput &&
|
|
212
|
+
appPlatform &&
|
|
213
|
+
appPlatform !== apps_1.AppPlatform.WEB &&
|
|
214
|
+
!appIdInput.includes(":web:")) {
|
|
215
|
+
return {
|
|
216
|
+
error: `Crashlytics setup is currently only supported for Web apps. No setup steps needed for non-Web app: ${appIdInput}. For Android and iOS, Crashlytics is configured directly in your app's build configuration (Gradle or CocoaPods/SPM).`,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
const effectiveProjectId = projectId || PLACEHOLDER_PROJECT_ID;
|
|
220
|
+
const finalAppId = resolvedAppId || PLACEHOLDER_APP_ID;
|
|
221
|
+
if (resolvedAppId && resolvedAppId !== PLACEHOLDER_APP_ID) {
|
|
222
|
+
try {
|
|
223
|
+
const sdkConfig = await (0, apps_1.getAppConfig)(resolvedAppId, apps_1.AppPlatform.WEB);
|
|
224
|
+
if ("apiKey" in sdkConfig) {
|
|
225
|
+
const resolvedProjectId = sdkConfig.projectId || projectId || PLACEHOLDER_PROJECT_ID;
|
|
226
|
+
return {
|
|
227
|
+
config: {
|
|
228
|
+
apiKey: sdkConfig.apiKey || PLACEHOLDER_API_KEY,
|
|
229
|
+
authDomain: sdkConfig.authDomain ||
|
|
230
|
+
(resolvedProjectId !== PLACEHOLDER_PROJECT_ID
|
|
231
|
+
? `${resolvedProjectId}.firebaseapp.com`
|
|
232
|
+
: PLACEHOLDER_AUTH_DOMAIN),
|
|
233
|
+
projectId: resolvedProjectId,
|
|
234
|
+
storageBucket: sdkConfig.storageBucket ||
|
|
235
|
+
(resolvedProjectId !== PLACEHOLDER_PROJECT_ID
|
|
236
|
+
? `${resolvedProjectId}.firebasestorage.app`
|
|
237
|
+
: PLACEHOLDER_STORAGE_BUCKET),
|
|
238
|
+
messagingSenderId: sdkConfig.messagingSenderId || PLACEHOLDER_MESSAGING_SENDER_ID,
|
|
239
|
+
appId: sdkConfig.appId || resolvedAppId,
|
|
240
|
+
},
|
|
241
|
+
detectedAppId: finalAppId,
|
|
242
|
+
detectedAppsNote,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
catch (err) {
|
|
247
|
+
logger_1.logger.debug("Failed to get app config:", err);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
config: {
|
|
252
|
+
apiKey: PLACEHOLDER_API_KEY,
|
|
253
|
+
authDomain: effectiveProjectId !== PLACEHOLDER_PROJECT_ID
|
|
254
|
+
? `${effectiveProjectId}.firebaseapp.com`
|
|
255
|
+
: PLACEHOLDER_AUTH_DOMAIN,
|
|
256
|
+
projectId: effectiveProjectId,
|
|
257
|
+
storageBucket: effectiveProjectId !== PLACEHOLDER_PROJECT_ID
|
|
258
|
+
? `${effectiveProjectId}.firebasestorage.app`
|
|
259
|
+
: PLACEHOLDER_STORAGE_BUCKET,
|
|
260
|
+
messagingSenderId: PLACEHOLDER_MESSAGING_SENDER_ID,
|
|
261
|
+
appId: finalAppId,
|
|
262
|
+
},
|
|
263
|
+
detectedAppId: finalAppId,
|
|
264
|
+
detectedAppsNote,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
exports.setup = (0, tool_1.tool)("crashlytics", {
|
|
268
|
+
name: "setup",
|
|
269
|
+
description: "Provides setup guides and onboarding instructions for integrating Firebase Crashlytics into web applications (Next.js, React, React Router, TanStack Router, Angular). Note: This tool only applies to Web apps; Crashlytics for iOS and Android is configured via native build tools (Gradle/CocoaPods/SPM). Includes Cloud project setup, API enablement, logging buckets and sinks, SDK initialization, framework-specific code snippets, sourcemap uploads, and test crash verification.",
|
|
270
|
+
humanReadableDescription: "Provide setup instructions and configuration guides for integrating Firebase Crashlytics into web applications. Note: Only applies to Web apps.",
|
|
271
|
+
inputSchema: zod_1.z.object({
|
|
272
|
+
appId: zod_1.z
|
|
273
|
+
.string()
|
|
274
|
+
.optional()
|
|
275
|
+
.describe("Firebase Web App ID (e.g. '1:1234567890:web:abcdef1234567890'). This tool only applies to Web apps. If omitted, the tool will attempt to detect a Web app from the active project."),
|
|
276
|
+
framework: FrameworkSchema,
|
|
277
|
+
}),
|
|
278
|
+
annotations: {
|
|
279
|
+
title: "Set up Crashlytics for Web",
|
|
280
|
+
readOnlyHint: true,
|
|
281
|
+
idempotentHint: true,
|
|
282
|
+
},
|
|
283
|
+
_meta: {
|
|
284
|
+
requiresProject: false,
|
|
285
|
+
requiresAuth: false,
|
|
286
|
+
},
|
|
287
|
+
isAvailable: async () => true,
|
|
288
|
+
}, async ({ appId: appIdInput, framework }, ctx) => {
|
|
289
|
+
const resolved = await resolveWebConfig(appIdInput, ctx.projectId);
|
|
290
|
+
if ("error" in resolved) {
|
|
291
|
+
return (0, util_1.mcpError)(resolved.error);
|
|
292
|
+
}
|
|
293
|
+
const { config, detectedAppId, detectedAppsNote } = resolved;
|
|
294
|
+
const effectiveProjectId = ctx.projectId || PLACEHOLDER_PROJECT_ID;
|
|
295
|
+
const frameworkSection = getFrameworkSection(framework);
|
|
296
|
+
const noteSection = detectedAppsNote ? `\n> **Note**: ${detectedAppsNote}\n` : "";
|
|
297
|
+
const content = `# Firebase Crashlytics for Web Apps - Setup Guide
|
|
298
|
+
|
|
299
|
+
> [!IMPORTANT]
|
|
300
|
+
Crashlytics setup via this tool only applies to **Web apps** (Next.js, React, Angular, React Router, and TanStack Router). Crashlytics for Android and iOS is configured directly via native build tools (Gradle, CocoaPods, Swift Package Manager).
|
|
301
|
+
|
|
302
|
+
Crashlytics for web apps uses Cloud Logging for telemetry storage and Cloud Storage for sourcemap storage under the hood.
|
|
303
|
+
${noteSection}
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
## Step 1: Configure Firebase / Cloud Project
|
|
307
|
+
|
|
308
|
+
### Option 1: Using Firebase Console (Recommended)
|
|
309
|
+
1. Navigate to the [Firebase Console Crashlytics page](https://console.firebase.google.com/u/0/project/_/crashlytics).
|
|
310
|
+
2. Select your project: \`${effectiveProjectId}\`.
|
|
311
|
+
3. Click **Set up** and follow the steps in the console.
|
|
312
|
+
|
|
313
|
+
### Option 2: Using Firebase CLI
|
|
314
|
+
Run the setup commands to enable Crashlytics:
|
|
315
|
+
\`\`\`bash
|
|
316
|
+
firebase crashlytics:setup ${detectedAppId} --project ${effectiveProjectId}
|
|
317
|
+
\`\`\`
|
|
318
|
+
> **Prerequisites**: Requires Firebase CLI v15.34.2+, Owner/Editor project permissions, and Blaze billing enabled.
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
## Step 2: Core SDK Installation & Initialization
|
|
323
|
+
|
|
324
|
+
### 1. Install Packages
|
|
325
|
+
Install the core Firebase package:
|
|
326
|
+
\`\`\`bash
|
|
327
|
+
npm install firebase
|
|
328
|
+
\`\`\`
|
|
329
|
+
|
|
330
|
+
### 2. Initialize Firebase App Singleton
|
|
331
|
+
Create a central configuration file (\`src/lib/firebase.ts\`):
|
|
332
|
+
\`\`\`typescript
|
|
333
|
+
// src/lib/firebase.ts
|
|
334
|
+
import { initializeApp, getApps, getApp } from 'firebase/app';
|
|
335
|
+
|
|
336
|
+
const firebaseConfig = {
|
|
337
|
+
apiKey: "${config.apiKey}",
|
|
338
|
+
authDomain: "${config.authDomain}",
|
|
339
|
+
projectId: "${config.projectId}",
|
|
340
|
+
storageBucket: "${config.storageBucket}",
|
|
341
|
+
messagingSenderId: "${config.messagingSenderId}",
|
|
342
|
+
appId: "${config.appId}"
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
// Guarantee singleton initialization
|
|
346
|
+
export const app = getApps().length === 0
|
|
347
|
+
? initializeApp(firebaseConfig)
|
|
348
|
+
: getApp();
|
|
349
|
+
\`\`\`
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
## Step 3: Framework-Specific Setup Guide
|
|
354
|
+
|
|
355
|
+
${frameworkSection}
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
## Step 4: Force an Initial Crash
|
|
360
|
+
|
|
361
|
+
To verify that crashes are properly delivered to Firebase Crashlytics, add a test error inside a user interaction handler (such as a button click):
|
|
362
|
+
|
|
363
|
+
\`\`\`typescript
|
|
364
|
+
throw new Error("Test Crash");
|
|
365
|
+
\`\`\`
|
|
366
|
+
|
|
367
|
+
1. Run your web application and trigger the crash by clicking the button.
|
|
368
|
+
2. Open the [Firebase Console Crashlytics dashboard](https://console.firebase.google.com/u/0/project/_/crashlytics).
|
|
369
|
+
3. Select project \`${effectiveProjectId}\` to view the newly logged crash report (note: reports may take 1-3 minutes to appear).
|
|
370
|
+
|
|
371
|
+
---
|
|
372
|
+
|
|
373
|
+
## Step 5: Source Map Uploading (Stack Trace De-obfuscation)
|
|
374
|
+
|
|
375
|
+
Upload your build source maps so Crashlytics displays original filenames, functions, and line numbers:
|
|
376
|
+
|
|
377
|
+
\`\`\`bash
|
|
378
|
+
firebase crashlytics:sourcemap:upload [buildOutputFolder] --app ${detectedAppId} --project ${effectiveProjectId}
|
|
379
|
+
\`\`\`
|
|
380
|
+
|
|
381
|
+
Provide the \`--clean\` flag to delete local source maps after uploading.
|
|
382
|
+
|
|
383
|
+
---
|
|
384
|
+
|
|
385
|
+
## Additional Configuration
|
|
386
|
+
|
|
387
|
+
- **Force 100% Sampling for Debugging**: Set \`self.FIREBASE_TELEMETRY_DEBUG = true;\` in browser code or DevTools console to force 100% telemetry collection for the current session.
|
|
388
|
+
- **Session Sampling Rate**: Configure session sampling (0% to 100%) in the Firebase Console (**Configure sampling**) or via the Firebase Telemetry Admin API.
|
|
389
|
+
- **Alerting**: Configure email alerts for new and regressed issues in Firebase Console under **Project Settings > Alerts**.
|
|
390
|
+
`;
|
|
391
|
+
return (0, util_1.toContent)(content);
|
|
392
|
+
});
|