Skip to content

Commit

Permalink
Defer injected scriptis to nextTick, so you can listen for sync errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed May 31, 2024
1 parent dcd9a90 commit 94499cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ export class FridaSession {
const agentSession = await this.getAgentSession(sessionId);

const script = await agentSession.createScript(fridaScript, {});
await script.loadScript();

setTimeout(async () => {
await script.loadScript();
}, 0);

return {
session: agentSession,
Expand Down Expand Up @@ -233,9 +236,12 @@ export class FridaSession {
const agentSession = await this.getAgentSession(sessionId);

const script = await agentSession.createScript(fridaScript, {});
await script.loadScript();

await hostSession.Resume(pid);
setTimeout(async () => {
await script.loadScript();
await hostSession.Resume(pid);
}, 0);

return {
pid,
session: agentSession,
Expand Down
6 changes: 2 additions & 4 deletions test/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe("Frida-JS", () => {
path.join(FIXTURES_BASE, `serve-${process.platform}-${process.arch}`),
[],
// Run an example script that always crashes:
"setTimeout(() => { throw new Error('Intentional script failure error'); }, 100);"
"throw new Error('Intentional script failure error');"
);
const messages: any[] = [];
session.onMessage((msg) => messages.push(msg));
Expand All @@ -134,9 +134,7 @@ describe("Frida-JS", () => {
type: 'error',
description: 'Error: Intentional script failure error',
stack: 'Error: Intentional script failure error\n' +
' at <anonymous> (/script1.js:1)\n' +
' at apply (native)\n' +
' at <anonymous> (frida/runtime/core.js:51)',
' at <eval> (/script1.js:1)',
fileName: '/script1.js',
lineNumber: 1,
columnNumber: 1
Expand Down

0 comments on commit 94499cc

Please sign in to comment.