OneDrive / onedrive-api-docs

Official documentation for the OneDrive API
MIT License
457 stars 231 forks source link

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

Open salahbm opened 11 months ago

salahbm commented 11 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 11 months ago

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

nayanprasad commented 8 months ago

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

rabbygit commented 8 months ago

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

AvulaPooja commented 7 months ago

Any solution for this issue ?

rabbygit commented 6 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.

talha-naseeb commented 1 month ago

Did you clear this bug ? Uncaught TypeError: e.data.indexOf is not a function at OneDrive.js:4:19110 this error encounter when i integrate onedrive in my react project , but it perfectly works in the template Code provided by Azrue...

AvulaPooja commented 1 month ago

Now , It is working fine, I'm not getting this - Uncaught TypeError: e.data.indexOf is not a function error anymore.

talha-naseeb commented 1 month ago

Now , It is working fine, I'm not getting this - Uncaught TypeError: e.data.indexOf is not a function error anymore.

what did you , install new version of it or anyother approch ?

AvulaPooja commented 1 month ago

v7.2 , I have used, it's working perfectly

talha-naseeb commented 1 month ago

Did you integrate one drive in React ?

On Wed, 25 Sept 2024 at 14:11, AvulaPooja @.***> wrote:

v7.2 , I have used, it's working perfectly

— Reply to this email directly, view it on GitHub https://github.com/OneDrive/onedrive-api-docs/issues/1763#issuecomment-2373509762, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5OGABXXE72VHHOIKWNP523ZYJ42JAVCNFSM6AAAAABOZGWKZGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNZTGUYDSNZWGI . You are receiving this because you commented.Message ID: @.***>

AvulaPooja commented 1 month ago

In Angular

talha-naseeb commented 1 month ago

I install 2 dependencies , msla-browser 3.24 and msal-react 2.1 Which version are you taking about?

On Wed, Sep 25, 2024, 2:21 PM AvulaPooja @.***> wrote:

In Angular

— Reply to this email directly, view it on GitHub https://github.com/OneDrive/onedrive-api-docs/issues/1763#issuecomment-2373533093, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5OGABRURM7KEHBAC453MWDZYJ575AVCNFSM6AAAAABOZGWKZGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNZTGUZTGMBZGM . You are receiving this because you commented.Message ID: @.***>

AvulaPooja commented 1 month ago
"@azure/msal-angular": "^3.0.23",
"@azure/msal-browser": "^3.22.0",
talha-naseeb commented 1 month ago

Did you wrap you component in AuthenticatedTemplate ? Or can you give me your script for testing ? really appericicate for that

AvulaPooja commented 1 month ago

Actually,I'm bit busy with different things , can u ping me tmrw for that

talha-naseeb commented 1 month ago

Okay Sure !

AvulaPooja commented 1 month ago

did u find the solution, to your issue

talha-naseeb commented 1 month ago

Yes , I mail the issue to Microsoft support. They said they will open the community to check the issue . And I found I one thing the script successfully run in edge but get issue in chrome

On Fri, Sep 27, 2024, 11:03 AM AvulaPooja @.***> wrote:

did u find the solution, to your issue

— Reply to this email directly, view it on GitHub https://github.com/OneDrive/onedrive-api-docs/issues/1763#issuecomment-2378463887, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5OGABTVFOQBS75LXIWXCD3ZYTYKTAVCNFSM6AAAAABOZGWKZGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNZYGQ3DGOBYG4 . You are receiving this because you commented.Message ID: @.***>