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

The Search API does not work on mobile devices. #3278

Closed
goldenages1989 opened this issue Dec 25, 2023 · 15 comments
Closed

The Search API does not work on mobile devices. #3278

goldenages1989 opened this issue Dec 25, 2023 · 15 comments
Assignees

Comments

@goldenages1989
Copy link

I wrote a script for Obsidian that retrieves archived data through an API.
It runs successfully on Mac, but when executed on iOS, it throws a TypeError: Load failed error.
My network connection is fine.

image

@jacksonh
Copy link
Contributor

Hi, you'll need to provide some more details so we can diagnose this. Search API definitely works on mobile you can open https://omnivore.app on mobile to verify. Do you have some sample code we could look at?

@goldenages1989
Copy link
Author

goldenages1989 commented Dec 26, 2023

I apologize for not providing enough information. Here is the code

async function fetchTraces(authToken) {
  let mappedResults = [];
  try {
    const cursor = 0;
    const limit = 10;
    const data = JSON.stringify({
    variables: {
      after: "0",
      first: 30,
      format: "",
      includeContent: false,
      query: "sort:updated-desc"
    },
    query: `query Search(
      $after: String
      $first: Int
      $query: String
      $includeContent: Boolean
      $format: String
    ) {
      search(
        first: $first,
        after: $after,
        query: $query,
        includeContent: $includeContent,
        format: $format
      ) {
        ... on SearchSuccess {
          edges {
            node {
                id
                title
                  slug
                  siteName
                  originalArticleUrl
                  url
                  author
                  updatedAt
                  description
                  savedAt
                  pageType
                  content
                  publishedAt
                  readAt
                  wordsCount
                  isArchived
                  readingProgressPercent
                  archivedAt
                  contentReader
            }
          }
          pageInfo {
            hasNextPage
            endCursor
            totalCount
          }
        }
        ... on SearchError {
          errorCodes
        }
      }
    }
  `,
  });
    const url = `https://api-prod.omnivore.app/api/graphql`;
    const completedTraceMetadata = await fetch(url, {
      method: 'POST',
      headers: {
        "Content-Type": "application/json",
        "Authorization": "${authToken}",
        "X-OmnivoreClient": "obsidian"
      },
      body: data
    }).then(function(response) {
      return response.json();
    });

@jacksonh
Copy link
Contributor

OK, my guess is what you are hitting here is a CORs error. Can you look in the developer console and on the network tab?

@goldenages1989
Copy link
Author

I can only access console information on my Mac computer. The console information on the mobile device cannot be obtained within Obsidian.

image

@jacksonh
Copy link
Contributor

Thanks, I didn't understand that you were running within Obsidian. I am still guessing this is related to CORS somehow. I wonder if on Mac Obsidian is proxying the fetch request to avoid CORs but on iOS its running through the browser.

Is this installed as a plugin?

@goldenages1989
Copy link
Author

goldenages1989 commented Dec 26, 2023

Yes, this is a obsidian plugin I wrote myself. In this plugin, I fetch data from Omnivore for processing.
I searched for some information about Obsidian CORS, and one suggestion was to switch the request api from fetch to requestUrl to handle CORS. After trying this, I found that it now throws a 500 error.

image
   const url = `https://api-prod.omnivore.app/api/graphql`;
    const RequestUrlParam = {
       url: url,
       method: 'POST',
       headers: {
        "Content-Type": "application/json",
        "Authorization": "${authToken}",
        "X-OmnivoreClient": "obsidian"
       },
       body: data
    };
    try {
       console.log("before http request");
       const response = await requestUrl(RequestUrlParam);
       console.log(response);
    } catch (e) {
      console.log(JSON.stringify(e));  
    }

@jacksonh
Copy link
Contributor

Can you paste the full stack here? (Make sure it doesn't have your token in it)

@goldenages1989
Copy link
Author

Do you means the result of console.log(e.stack)?

@jacksonh
Copy link
Contributor

Do you means the result of console.log(e.stack)?

Yeah

@goldenages1989
Copy link
Author

That's the only information available

image

@jacksonh
Copy link
Contributor

Long shot because its hard to tell from our logs, but there was a request right around that time with an invalid API key. Maybe in the code update the authToken variable was changed?

Also, your key was visible in a previous screenshot, so you should probably delete that key on our API keys page.

@goldenages1989
Copy link
Author

goldenages1989 commented Dec 26, 2023

Indeed, it was indeed the token error that caused the problem. Now the API calls are working correctly. Thank you so much for your guidance!

@jacksonh
Copy link
Contributor

Awesome, please let us know more about your tool when you have it ready to demo...if you plan on sharing it. Might want to checkout our Discord also.

I'll close this one out, but let me know if there are still issues

@goldenages1989
Copy link
Author

It is a plugin that pulls out articles from the Omnivore archive that you have read on a given day and writes them into your Obsidian journal. I wrote it based on this plugin. If anyone is interested, I would be happy to share it.

@jacksonh
Copy link
Contributor

I think people would really like this actually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants