Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
debug widget
Browse files Browse the repository at this point in the history
shakyShane committed Jan 24, 2025
1 parent 0810474 commit e96a751
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 6 additions & 4 deletions special-pages/pages/new-tab/app/telemetry/Debug.js
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@ import { useTelemetry } from '../types.js';
import { useCustomizer } from '../customizer/components/CustomizerMenu.js';
import { Telemetry } from './telemetry.js';

export function DebugCustomized({ index }) {
const [isOpen, setOpen] = useState(false);
export function DebugCustomized({ index, isOpenInitially = false }) {
const [isOpen, setOpen] = useState(isOpenInitially);
const telemetry = useTelemetry();
useCustomizer({
title: '🐞 Debug',
@@ -47,11 +47,13 @@ function useEvents(ref, telemetry) {
useEffect(() => {
if (!ref.current) return;
const elem = ref.current;
const pre = '```json\n';
const post = '\n```\n';
function handle(/** @type {CustomEvent<any>} */ { detail }) {
elem.value += JSON.stringify(detail, null, 2) + '\n\n';
elem.value += pre + JSON.stringify(detail, null, 2) + post;
}
for (const beforeElement of telemetry.eventStore) {
elem.value += JSON.stringify(beforeElement, null, 2) + '\n\n';
elem.value += pre + JSON.stringify(beforeElement, null, 2) + post;
}
telemetry.eventStore = [];
telemetry.storeEnabled = false;
8 changes: 7 additions & 1 deletion special-pages/pages/new-tab/app/widget-list/WidgetList.js
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import { ErrorBoundary } from '../../../../shared/components/ErrorBoundary.js';
import { Centered, VerticalSpace } from '../components/Layout.js';
import { INLINE_ERROR } from '../InlineErrorBoundary.js';
import { DebugCustomized } from '../telemetry/Debug.js';
import { useEnv } from '../../../../shared/components/EnvironmentProvider.js';

/**
* @param {string} id
@@ -42,6 +43,7 @@ export async function widgetEntryPoint(id, didCatch) {
export function WidgetList() {
const { widgets, widgetConfigItems, entryPoints } = useContext(WidgetConfigContext);
const messaging = useMessaging();
const { env } = useEnv();

/**
* @param {string} message
@@ -90,7 +92,11 @@ export function WidgetList() {
</WidgetVisibilityProvider>
);
})}
<DebugCustomized index={widgets.length} />
{env === 'development' && (
<Centered data-entry-point="debug">
<DebugCustomized index={widgets.length} isOpenInitially={true} />
</Centered>
)}
</Fragment>
);
}

0 comments on commit e96a751

Please sign in to comment.