Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'xml-prune' — logging, new Request() #289

Closed
2 tasks done
AdamWr opened this issue Feb 6, 2023 · 0 comments
Closed
2 tasks done

Fix 'xml-prune' — logging, new Request() #289

AdamWr opened this issue Feb 6, 2023 · 0 comments

Comments

@AdamWr
Copy link
Member

AdamWr commented Feb 6, 2023

  • Fix issue with logging
  • Fix issue with not pruning if new Request is used

Currently if type of request is not a text then there are errors and script might not work correctly.
Steps to reproduce:

  1. Add this rule:
example.org#%#//scriptlet('xml-prune')
  1. Go to - https://example.org/
  2. Run in console:
(() => {
  const xhr = new XMLHttpRequest();
  xhr.open('GET', '/');
  xhr.responseType = 'blob';
  xhr.onload = () => {
    console.log('test');
  };
  xhr.send();
})();

There is an error - Uncaught TypeError: text.trim is not a function

Screenshot

image


Another issue is that, if Request constructor is used in fetch then request is not pruned/checked.

(async () => {
  const request = new Request('/');
  const fetchContent = await fetch(request);
  const text = await fetchContent.text();
//...
})();
@adguard-bot adguard-bot assigned zzebrum and unassigned zzebrum Feb 6, 2023
@adguard-bot adguard-bot changed the title Improve xml-prune - fix issue with logging Fix 'xml-prune' — logging, new Request() Feb 6, 2023
adguard pushed a commit that referenced this issue Feb 17, 2023
Squashed commit of the following:

commit 785b89b
Merge: 59627ef 9b1206d
Author: Adam Wróblewski <adam@adguard.com>
Date:   Thu Feb 16 13:23:39 2023 +0100

    Merge branch 'master' into fix/AG-19572

commit 59627ef
Author: Adam Wróblewski <adam@adguard.com>
Date:   Wed Feb 15 16:47:05 2023 +0100

    Make the structure less complicated
    Add more specific comment

commit 068f67f
Author: Adam Wróblewski <adam@adguard.com>
Date:   Tue Feb 14 18:30:29 2023 +0100

    Log the name of the scriptlet
    Set force flag to true

commit b2e7d1c
Author: Adam Wróblewski <adam@adguard.com>
Date:   Mon Feb 13 19:03:30 2023 +0100

    Use native startsWith() and endsWith() methods
    Add a comment about checking type of text
    Use logMessage instead of console.log
    Modify logMessage function to allow logs other type than string
    Fix test

commit 1a4cfcb
Author: Adam Wróblewski <adam@adguard.com>
Date:   Wed Feb 8 18:18:11 2023 +0100

    xml-prune scriptlet - fix issue with logging
    Fix issue with not pruning new Request()
    Improve logging a bit - log DOM tree to console
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants