Sunday, 19 November 2023

TipTap/ProseMirror wrap selection with arbitrary text

I am using TipTap to write markdown text (not html).

I'm doing this by not using any extensions like Bold and just doing them myself, and then using the getText() function.

All this works very well for my simple use case, even though I'm sure it's not ideal without using proper extensions etc.

(Note that I want all markdown to be visible, and not interpreted by the editor, which is why im doing it this way)

The problem is my wrapping/unwrapping code has some bugs, specifically related to going out of bounds.

The main time this occurs is if there is only a single word being highlighted, as well as multiple words but highlighting the last word

TypeError: Cannot read properties of undefined (reading 'nodeSize')

Is there a simpler way to do this, or what am I missing about my current implementation? I found it weird that the selections are not starting at 0 if i highlight just one word

    const wrapUnwrap = marker => {
      const { state, view } = toRaw(editor.value);
      const { from, to } = state.selection;
      const len = marker.length;

      // exit if nothing selected
      if (from === to) {
        return;
      }

      // there is a current bug here where there are "node size" errors if you
      // try to select a single word and make it bold... as well as the last word
      let textBefore, textAfter;
      try {
        textBefore = state.doc.textBetween(from - len, from);
        textAfter = state.doc.textBetween(to, to + len);
      } catch (e) {
        console.log(e);
        return;
      }
      let tr = state.tr;

      if (textBefore === marker && textAfter === marker) {
        tr.delete(to, to + len);
        tr.delete(from - len, from);
      } else {
        tr.insertText(marker, to, to);
        tr.insertText(marker, from, from);
      }
      view.dispatch(tr);
    };

    const makeBold = () => {
      wrapUnwrap("**");
    };

    const makeItalic = () => {
      wrapUnwrap("*");
    };


from TipTap/ProseMirror wrap selection with arbitrary text

How do I solve an Arkose FunCaptcha on LinkedIn using 2Captcha when the CAPTCHA is embedded within an iframe?

I am attempting to automate solving CAPTCHAs when logging into LinkedIn via 2Captcha in my Python/Selenium/Google Chrome script.

To do so, per the answer of a previous question I asked, I load the CRX file for the 2Captcha Chrome Extension when instantiating my webdriver, and enabling autosolve for all CAPTCHAs.

However, for LinkedIn, the extension is unable to detect the CAPTCHA because it is inside an <iframe></iframe> element of the webpage. To bypass, this, I added the following to my Python script to detect and solve the CAPTCHA:

This script below still does not detect and properly solve FunCaptchas. May I know what I can do to detect and solve LinkedIn CAPTCHAs that are inside an <iframe></iframe>? For reference, an image of what this CAPTCHA and a snippet of LinkedIn's code (below mine) are attached.

My Python Code:

try:
    solver = TwoCaptcha('<API_KEY>')
    captcha = driver.find_element(By.XPATH, 
                                    "//input[@name='captchaSiteKey']")
    captcha_sitekey = captcha.get_attribute('value')
    iframe = driver.find_element(By.XPATH, "//iframe")
    iframe_source = iframe.get_attribute('src')
    driver.switch_to.frame(iframe)
    
    print(f'IFRAME Source: {iframe_source}')
    print(f'CAPTCHA SiteKey: {captcha_sitekey}')

    time.sleep(60)
    result = solver.funcaptcha(sitekey=captcha_sitekey, 
                                url=iframe_source)
    
    for key in result:
        print(f'{key}: {result[key]}')
    
    print('We found and solved a CAPTCHA.')
    driver.switch_to.default_content()
except Exception as e:
    print(f'We could not solve the CAPTCHA because {str(e)}, '
          f'{traceback.print_exc}')

(I did not write it in the block of code above, but I'm importing the traceback, 2captcha-python, and selenium modules.

LinkedIn's HTML on the CAPTCHA page:

<iframe class="" id="captcha-internal" src="./Security Verification _ LinkedIn_files/funCaptchaInternal.html"
    frameborder="0" role="presentation" title="Captcha Challenge" height="290" width="302"></iframe>
<form method="post" class="hidden" id="captcha-challenge" action="https://www.linkedin.com/checkpoint/challenge/verify">
    <input type="hidden" name="csrfToken" value="ajax:6505936439590984220"><input type="hidden" name="captchaSiteKey"
        value="3117BF26-4762-4F5A-8ED9-A85E69209A46"><input type="hidden" name="challengeId"
        value="AQFvUtZMWireaAAAAYvTP-Lq8KvlyrCr7xCgZlth6uf4UoJSq7UrP1-4bNpriHtPql8mOpZipQF3qa1vNAec2TT9aef2xMVB0Q"><input
        type="hidden" name="language" value="en-US"><input type="hidden" name="displayTime"
        value="AgFP_RD3wseHwQAAAYvTP-L3CpYje8Fh1rkGPsUfvp7WGYv0NvYEqR_gAaCDCew"><input type="hidden"
        name="challengeType" value="AgFU-zncyoLVdAAAAYvTP-L66dj0drF5826EpedJld3sNEQ0b8diSPFWlBU"><input type="hidden"
        name="challengeSource" value="AgGudd74ELMaKQAAAYvTP-L9K5-uGH1mPDpZy1yUGcdWEbCi3jtReJS_a-ufgicE"><input
        type="hidden" name="requestSubmissionId"
        value="AgF0RnGQ2BTi9QAAAYvTP-MA56TcJxjPSm3P71dof2-LrpBUMFM96V4_2m0pYDnLWnYMTPz9HIZ-TuCX35YFJgKBYom7WXc3eTGfrQ"><input
        type="hidden" name="captchaUserResponseToken" value=""><input type="hidden" name="challengeData"
        value="AgFlYfn-cheGuwAAAYvTP-LySUtucNcd5hW7d3PzwesMuCW97DRwpH_XItP5Ynt4E_dL4mZC18kF-5UGtjZ_l25oIZXIrhpW_qjH84--g65ZGktWQJloVkNrMiY3BrOTB1PuqhvwDnYhJj3o-jM54s5Ap1-0U7zDiU6lgAkA92Ez01S2-PBr15R44ZrVoFQPuRhOsUKQdSjREh4sPw6zjyx-9EYXEgPwnwWbCNjT8GpYr1GkobR0bQsa0RLjgkSOQ7KxV4iTVoYYHgt7UFssZQykI0PdVypaYVft3OoZTewLoz2Tg6GcIU58TItd4ulUP8gGj4NpKsQiMtqxf9mxs1hxkKtoOt29ZJ3RPa0Ge9z0bUYzjKChJNdORYHzSJcmnBPY4az1z3mw4hh7F0wbzZouuAb6yCwGtX_6sEnuaewCHBSaEbv-VwmNgDGk8-k_z-seh_2z2Q-s5gPanbEPBjhhseq9OBweFlXmSRf6h9KTlcizSGgBx7Yz9YBirkob2ukkxuU9yhmZ9911cUVMJ-ZaQU0jNOZW9PEX4ZLinEAWi5ei3X2bXfIc3lVhQ89RN-6t9G9uRFbOKOcrisiPt2MgDTBVni0QLkPcDOQyAahyxiTwJg8ksp3cPi16xZd4zr2VHiIT0Dm8CuI4GPImNdfMKjqZWuPjS7KC0_CtHvXa03cwfQAXSYGzDIX7obdutQ2XWT3JyXF4sz3o03bPIn2p0f7Aejd2yI6AH5krsacMqaVrSfLjSBq4xRBjLLg"><input
        type="hidden" name="pageInstance"
        value="urn:li:page:d_checkpoint_ch_captchaV2Challenge;KXxlvP5+SpygwcfBd+7rDg=="><input type="hidden"
        name="challengeDetails"
        value="AgFwKVDCcGn56wAAAYvTP-L1wL8sH9K8QYfqk4ydRmaR9VTdhiElPBT1pJ9zSFYaYZU7F6ulGXRJjDXGNCiOU_57wWr4ae19I_rc9qVKYlm5ggO43Yr8Q_AJX6TOv5s_fqbcAEakFbLgVvIu46NVK_TI1lwtIXay"><input
        type="hidden" name="failureRedirectUri"
        value="AgFg3MLPYMreRAAAAYvTP-MC_VIvK3O8g0pYH_FBHDR5q1XBY77au_DHDHrV1c78mXMKKhjrXIC-8vKyXQZuC7ashO7hSP0qRmwORfm-ECf1Tjuisx6n_Q"><input
        type="hidden" name="signInLink" value="/checkpoint/lg/login?trk=homepage-basic_sign-in-submit"><input
        type="hidden" name="joinNowLink" value="/signup/cold-join?source=homepage-basic_sign-in-submit"><input
        type="hidden" name="_s" value="CONSUMER_LOGIN">
</form>

LinkedIn CAPTCHA image.



from How do I solve an Arkose FunCaptcha on LinkedIn using 2Captcha when the CAPTCHA is embedded within an iframe?

What exactly PyCharm Django Test run configuration do

I have a custom test command in my Django project:

class Command(test.Command):
    def add_arguments(self, parser):
        super(Command, self).add_arguments(parser)
        parser.add_argument(
            "--fit",
            action="store_true",
            help="Fit persistent tests instead of checking them.",
        )

    def handle(self, *test_labels, **options):
        if options["fit"]:
            ...
        super(Command, self).handle(*test_labels, **options)

It works when running from the console, e.g. python manage.py test --fit.

However, when I'm using a PyCharm Django Tests configuration, it does not execute the handle(...) method. I can add --fit flag as an option and I can't add some random --qwerty flag. So, it means that the command is registered. While running in debug mode, I could reach the point in the add_arguments(...), but not in the handle(...) (as well as not in the django.core.management.commands.test.Command.handle(..), by the way).

The only problem is that PyCharm executes this command some other way, without calling handle(...) method. So the question is - maybe someone know, what PyCharm is actually calling?



from What exactly PyCharm Django Test run configuration do