OneDrive / onedrive-api-docs

Official documentation for the OneDrive API
MIT License
447 stars 228 forks source link

Error thrown in Js Sdk: e.data.indexOf is not a function #1290 #1763

Open salahbm opened 7 months ago

salahbm commented 7 months ago

Category

Expected or Desired Behavior

Sign In and Save to OneDrive

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script type="text/javascript" src="https://js.live.net/v7.2/OneDrive.js" async defer></script>
    <title>Vite + React</title>
  </head>
  <body>
    <div id="root"></div>
    <input id="fileUploadControl" name="fileUploadControl" type="file" />
    <button onclick="launchSaveToOneDrive()">Save to OneDrive</button>

    <script type="text/javascript">
      function launchSaveToOneDrive() {
        console.log('Launching save to OneDrive...');
        try {
          let odOptions = {
            clientId: "b1a649b1-9c86-4a97-8780-a92ea687bf32",
            action: "save",
            sourceInputElementId: "fileUploadControl",
            fileName: "test.txt",
            openInNewWindow: false,
            advanced: {
              redirectUri: "http://localhost:5173"
            },
            success: function(files) {
              console.log('Save successful:', files);
            },
            progress: function(percent) {
              console.log('Save progress:', percent);
            },
            cancel: function() {
              console.log('Save canceled');
            },
            error: function(error) {
              console.error('Save error:', error);
            }
          };

          OneDrive.save(odOptions);
        } catch (error) {
          console.error('Error launching save operation:', error.message);
        }
      }
    </script>
  </body>

ERROR

1. OneDrive.js:4 Uncaught TypeError: e.data.indexOf is not a function
    at OneDrive.js:4:19110

 2.  Failed due to Unknown Error: Error at new e (https://js.live.net/v7.2/OneDrive.js:4:32744) at https://js.live.net/v7.2/OneDrive.js:4:19308

Thank you.

jainam-shah-cygnet commented 7 months ago

I am facing the same error while I want to open oneDrive for pick a file. (OneDrive.open(odOptions);)

nayanprasad commented 4 months ago

did you find any solution for this? i'm also getting the same error

rabbygit commented 4 months ago

I am encountering the same problem while attempting to call OneDrive.open(options) function.

AvulaPooja commented 3 months ago

Any solution for this issue ?

rabbygit commented 2 months ago

I think I've found the root cause of this issue. The u.onMessage event listener https://prnt.sc/xUZxD26SJlzI can be fired from another window pop-up. The e.data is supposed to be a JSON string https://prnt.sc/Z0MndPAi7x3I but in my case, the u.onMessage event listener is fired from the react-dev-tools and the e.data becomes an object https://prnt.sc/rfQsntoYzT30. it causes the error. We can fix the issue by adding an extra string type check https://prnt.sc/R6EDK-bZXz2x.