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

Feat: screenshots #670

Merged
merged 18 commits into from
Apr 21, 2022
Merged

Feat: screenshots #670

merged 18 commits into from
Apr 21, 2022

Conversation

vaind
Copy link
Collaborator

@vaind vaind commented Mar 30, 2022

Closes #284

TODO:

@bruno-garcia
Copy link
Member

We can also replace this sample then:

public void CaptureMessageWithScreenshot() => StartCoroutine(CaptureScreenshot());

src/Sentry.Unity/Integrations/IApplication.cs Outdated Show resolved Hide resolved
src/Sentry.Unity/ScreenshotAttachment.cs Show resolved Hide resolved
src/Sentry.Unity/ScreenshotAttachment.cs Outdated Show resolved Hide resolved
src/Sentry.Unity/ScreenshotAttachment.cs Outdated Show resolved Hide resolved
@lucas-zimerman
Copy link
Collaborator

Out of curiosity, does this feature works with UWP? I recall on Xamarin that when I tried to take a screenshot it usually freezes the app on UWP so I just disabled it on that platform 😅

@vaind
Copy link
Collaborator Author

vaind commented Apr 4, 2022

We can also replace this sample then:

public void CaptureMessageWithScreenshot() => StartCoroutine(CaptureScreenshot());

Replace by what though? I'd actually remove that.

@vaind
Copy link
Collaborator Author

vaind commented Apr 4, 2022

Out of curiosity, does this feature works with UWP? I recall on Xamarin that when I tried to take a screenshot it usually freezes the app on UWP so I just disabled it on that platform 😅

While UWP isn't officially supported (a.k.a tested), the screenshot attachment seems to work fine:

{"type":"attachment","length":100262,"filename":"screenshot.jpg","attachment_type":"event.attachment","content_type":"image/jpeg"}

Though I can't verify if the actual screenshot looks reasonable because there are HTTP Request errors despite enabling some internet-related permissions in the player settings:

Sentry: (Error) Failed to send cached envelope: C:/Users/dlugo/AppData/Local/Packages/Template2D_pzq3xp76mxafg/LocalState\Sentry\618762E37120B6E01219C43B9076FFEC1ACE8406\__processing\1649084082_-4848__1273990338.envelope, type: HttpRequestException, retrying after a delay. System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Error: NameResolutionFailure
  at System.Net.HttpWebRequest.EndGetRequestStream (System.IAsyncResult asyncResult) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Func`2[T,TResult].Invoke (T arg) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.Tasks.TaskFactory`1+<>c__DisplayClass35_1[TResult].<FromAsyncImpl>b__1 (System.IAsyncResult iar) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.Windows.WebCam.PhotoCapture+OnCaptureResourceCreatedCallback.Invoke (UnityEngine.Windows.WebCam.PhotoCapture captureObject) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Net.SimpleAsyncCallback.Invoke (System.Net.SimpleAsyncResult result) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Net.HttpWebRequest.SetWriteStreamError (System.Net.WebExceptionStatus status, System.Exception exc) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Net.WebConnection.InitConnection (System.Net.HttpWebRequest request) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Net.WebConnection.<SendRequest>b__41_0 (System.Object o) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ContextCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00000] in <00000000000000000000000000000000>:0 

Comment on lines +42 to +43
[field: SerializeField] public int ScreenshotMaxWidth { get; set; }
[field: SerializeField] public int ScreenshotMaxHeight { get; set; }
Copy link
Contributor

@bitsandfoxes bitsandfoxes Apr 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about dealing with absolute pixel sizes here. It does not take into account devices with different aspect ratios or switching from portrait to landscape.
Maybe we should start with a ratio instead e.g. "half the original resolution".

Copy link
Collaborator

@lucas-zimerman lucas-zimerman Apr 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use a single parameter for Width/Height that gets applied to the highest value and if the image is bigger than the given maximum value, resize it while keeping the aspect ratio.

Sample code that I used to use for getting a new size for the image

        private static SKImageInfo GetResizedMeasure(int width, int height, int newMax)
        {
            double ratio;
            if (width > newMax)
            {
                ratio = (double)newMax / width;
                height = (int)(height * ratio);
                width = (int)(width * ratio);
            }
            if (height > newMax)
            {
                ratio = (double)newMax / height;
                width = (int)(width * ratio);
                height = (int)(height * ratio);
            }
            return new SKImageInfo(width, height, SKColorType.Rgb565);
        }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've discussed in the call to align across other SDKs. @bitsandfoxes is going to gather inputs

src/Sentry.Unity/ScreenshotAttachment.cs Show resolved Hide resolved
@vaind
Copy link
Collaborator Author

vaind commented Apr 20, 2022

I've disabled for WebGL where the screenshots consistently don't work (they're black), and updated the tooltip with more information. If you think that's OK for now, please merge @bitsandfoxes or @bruno-garcia

@vaind vaind merged commit d49cf66 into main Apr 21, 2022
@vaind vaind deleted the feat/screenshots branch April 21, 2022 15:27
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

Successfully merging this pull request may close these issues.

Add AttachScreenshot option
5 participants