Skip to content

Fix 'isValidCallback' — returns false for functions without a prototype #561

@AdamWr

Description

@AdamWr

Related issue - AdguardTeam/AdguardFilters#231983, though there is another problem that scriptlet is not injected into iframe.

Steps to reproduce:

  1. Add to user rules:
example.org#%#//scriptlet('adjust-setTimeout', '/./', '7000', '0.001')
  1. Navigate to - https://example.org/
  2. Run in console:
const logTest = () => console.log('Test');
Object.setPrototypeOf(logTest, {foo: 1});
setTimeout(logTest, 7000)

Delay in setTimeout is not adjusted because callback instanceof Function returns false in:

export const isValidCallback = (callback: unknown): boolean => {
return callback instanceof Function

I guess we can change it to typeof callback === 'function'.


And probably for such cases we need to use Function.prototype.toString.call(callback); instead of callback.toString().
The former returns () => console.log('Test'), but the latter [object Function] in this case.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions